<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi,<div><br></div><div>My assumption was wrong… The following code is just a macro that generate 100000 functions and it compiles fine.  </div><div>At least you can have 100000 functions so it should be ok!!! The problem was that I was calling the |max| function. In the javascript backend this function only takes two args. In the scheme world it is an n-ary function. </div><div><br></div><div>Sorry for pointing out the wrong thing.</div><div> </div><div><div><font face="Courier">(declare (standard-bindings)</font></div><div><font face="Courier">        (extended-bindings)</font></div><div><font face="Courier">        (fixnum) (not safe))</font></div></div><div><br></div><div><div><font face="Courier">(define-macro (generate-dummy-function-defs)</font></div><div><font face="Courier">  </font></div><div><font face="Courier">  ; reverse is not available (in target js)</font></div><div><font face="Courier">  (define (myreverse l)</font></div><div><font face="Courier">    (define (iter a b)</font></div><div><font face="Courier">      (if (null? a) b</font></div><div><font face="Courier">        (iter (cdr a) (cons (car a) b))))</font></div><div><font face="Courier">    (iter l (list)))</font></div><div><font face="Courier">  </font></div><div><font face="Courier">  </font></div><div><font face="Courier">  (define (iota n)</font></div><div><font face="Courier">    (myreverse (riota n)))</font></div><div><font face="Courier">  </font></div><div><font face="Courier">  </font></div><div><font face="Courier">  (define (riota n)</font></div><div><font face="Courier">    (if (= n 0) </font></div><div><font face="Courier">        (cons 0 '())</font></div><div><font face="Courier">      (cons n (riota (- n 1)))))</font></div><div><font face="Courier">  </font></div><div><font face="Courier">  `(begin</font></div><div><font face="Courier">     ,@(map (lambda (i)</font></div><div><font face="Courier">              `(define (,(string->symbol (string-append “fct” (number->string i))))</font></div><div><font face="Courier">                 ,i))</font></div><div><font face="Courier">            (iota 100000))))</font></div><div><font face="Courier"><br></font></div><div><font face="Courier"><br></font></div><div><font face="Courier">(generate-dummy-function-defs)</font></div></div><div><font face="Courier"><br></font></div><div><font face="Courier"><br></font></div><div>François</div><div><br><div><div>On Jan 24, 2014, at 10:52 AM, Francois Magnan <<a href="mailto:magnan@categoricaldesign.com">magnan@categoricaldesign.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Marc,<div><br></div><div>It seems I stumbled on a problem with the javascript backend. When I compile my program I get an error message from gsc:</div><div><br></div><div><div style="margin: 0px; font-size: 13px; font-family: Monaco;">*** ERROR IN c#univ-dump-procs -- Wrong number of arguments passed to procedure</div><div style="margin: 0px; font-size: 13px; font-family: Monaco;">(#<procedure #2></div><div style="margin: 0px; font-size: 13px; font-family: Monaco;"> '#(#(target js #<procedure #3> #<procedure #4> #<procedure #5 c#target.dump> 5 #<procedure #6 c#target.prim-info> #<procedure #7 ...</div><div style="margin: 0px; font-size: 13px; font-family: Monaco;"> '#<procedure #8></div><div style="margin: 0px; font-size: 13px; font-family: Monaco;"> '(("Gambit_" "stack") "[" (("Gambit_" "sp") (-2)) "]")</div><div style="margin: 0px; font-size: 13px; font-family: Monaco;"> '(("Gambit_" "stack") "[" (("Gambit_" "sp") (-1)) "]")</div><div style="margin: 0px; font-size: 13px; font-family: Monaco;"> '(("Gambit_" "stack") "[" (("Gambit_" "sp") (-4)) "]")</div><div style="margin: 0px; font-size: 13px; font-family: Monaco;"> ‘("Gambit_" ("r" 1)))</div></div><div style="margin: 0px; font-size: 13px; font-family: Monaco;"><br></div><div style="margin: 0px;">If I comment out some function definitions in my code I don’t get the error. It looks to me like there is a limit to the number of procedures that can be handled in a given file. It seems to be related to the maximum number of arguments a function can take.</div><div style="margin: 0px;"><br></div><div style="margin: 0px;">Is there a way to split the code into multiple files?</div><div style="margin: 0px;"><br></div><div style="margin: 0px;">Thank you,</div><div style="margin: 0px;">Francois Magnan</div><div><br></div><div><br></div><div><br><div><div>On 2013-11-23, at 09:54, Marc Feeley <<a href="mailto:feeley@iro.umontreal.ca">feeley@iro.umontreal.ca</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br>On Nov 22, 2013, at 4:52 PM, Mikael <<a href="mailto:mikael.rcv@gmail.com">mikael.rcv@gmail.com</a>> wrote:<br><br><blockquote type="cite">(For general interest)<br><br>2013/11/22 Marc Feeley <<a href="mailto:feeley@iro.umontreal.ca">feeley@iro.umontreal.ca</a>><br><br>On Nov 22, 2013, at 1:40 AM, Mikael <<a href="mailto:mikael.rcv@gmail.com">mikael.rcv@gmail.com</a>> wrote:<br><br><blockquote type="cite">Francois,<br><br>Two Q:s:<br><br>First, when you got a very basic sample app like a DOM-based hangman going, feel free to share code<br><br>Second, how is the type mapping - fixnums, flonums, bignums all wrapped to JS double, Scheme string and vector to JS string and vector?<br></blockquote><br>(1)<span class="Apple-converted-space"> </span><br>The data representation is customizable with two options for each type.  There is a "natural" mapping (Scheme number -> JS number, Scheme vector -> JS array, etc) and one which uses classes.<br><br>(2)<span class="Apple-converted-space"> </span><br>Note that the natural mapping may violate some of the Scheme semantics.  For example, JS numbers don't carry the concept of exactness, and JS strings are immutable whereas Scheme strings are mutable.  On the other hand the natural mapping may be useful in cases where some details of the Scheme semantics are not important (the generated JS code is easier to read/understand, the generated JS code can be more easily interfaced with existing JS libraries, etc).  A mapping which respects the Scheme semantics is:<br><br>- Fixnums are mapped to JS numbers<br>- Booleans are mapped to JS booleans<br>- Symbols are mapped to JS strings<br>- Vectors are mapped to JS arrays<br>- Procedures are mapped to JS functions<br>- Strings, characters, flonums (and other numbers), and pairs are implemented with JS classes<br><br><br><br>Wait, first(1) you suggest there's a customizable option, and then second(2) you outline a holistic approach for Scheme-JS type mapping.<br><br>How is it? And if anything is configurable, where's the switch?<br><br></blockquote><br>The source code of the universal backend was written to support both data representations, selectable for each type.  So it is "customizable" in the sense that you simply have to change a single definition in _t-univ.scm to select the representation for each Scheme type (see the top of the file, e.g. (define (univ-flonum-representation ctx) 'class) ).  It would be possible to expose these settings to the user, although it is not clear what is the best way to do that.  Perhaps that could be part of the target's name, e.g.<br><br>  gsc -target js     file.scm<br>  gsc -target js-foo file.scm<br>  gsc -target js-bar file.scm<br><br>where foo and bar would indicate a particular choice of data representations that make some compromises (e.g. incomplete support of the Gambit specific features, lesser performance for some of the Gambit specific features, etc).<br><br><blockquote type="cite"><br>Unfortunately, this mapping makes it expensive to implement some Gambit specific operations, such as ##subtype, ##subtype-set! and<br><br>Didn't even hear about ##subtype* til now - Any use of JS turns out to be for some special purpose anyhow, so that there's some real corner case of Scheme execution in this environment that has a low performance is really completely cool.<span class="Apple-converted-space"> </span><br></blockquote><br>The problem is that ##subtype, etc are used in the implementation of the Gambit runtime library.  For example, ##subtype is used in the implementation of the procedure equal?-hash and some type predicates.  So even if ##subtype is not used directly by users, some user callable procedures in the Gambit runtime library do use ##subtype.<br><br><blockquote type="cite"><br>##vector-ref.<br><br>Wait, why, can't this just be ordinarily expanded to JS' variable[index]?<br></blockquote><br>Because ##vector-ref is used to access slots of many Gambit objects, not just vectors.  For example the slot at index 0 of a symbol is the symbol's name, and the slot at index 0 of a structure is the type descriptor:<br><br><blockquote type="cite">(##vector-ref 'foo 0)                                       <br></blockquote>"foo"<br><blockquote type="cite">(##vector-ref (current-input-port) 0)                       <br></blockquote>#<type #4 device-port><br><br>If a Scheme datatype is represented using a JS class (for example a Scheme symbol is represented with a JS class with a "name" property), then (##vector-ref sym 0) if it is translated to sym[0] will not retrieve the name of the symbol.  It would be possible to avoid this problem by using JS arrays to represent all memory allocated Gambit objects, but this would not be a natural translation (harder to understand the generated code, harder to write external JS code accessing the data representation, etc).  Another approach would be to put some type dispatch logic in ##vector-ref to do the right thing with symbols, structures, etc, but this would slow down ##vector-ref.<br><br>Of course another approach would be to refactor the Gambit runtime system to replace such "unclean" uses of ##vector-ref by calls to type specific primitives.  It is not clear how much work this would be (primitives have to be added to the compiler and the runtime system has to be refactored).<br><br><blockquote type="cite"><br>So it may be necessary to implement non immediate data (vectors, structures, etc) uniformly with classes when using the standard Gambit runtime system.  <br><br>I haven't explored this aspect much, but it may be that supporting all the Gambit primitives isn't practical.<br><br>(same note as above re special purpose here)<br><br>A solution may be to have two modes (Standard Scheme and Gambit Scheme) so the user can select the best mode for his needs.<br><br>What would the difference be approx here?<br></blockquote><br>Hard to say.  The Gambit runtime system has to be examined carefully to see what would break for a particular choice of representation.  For example, in a mode where number exactness is not supported (allowing all Scheme numbers to be represented with the JS "number" type, except for complex numbers), there will be a major impact on the numerical functions in lib/_num.scm .  Some (how many?) will have to be modified to be consistent with the fact that there is no exactness.  Should the lack of exactness be handled the same as treating all numbers as inexact numbers? etc.<br><br>Marc<br><br>_______________________________________________<br>Gambit-list mailing list<br><a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br><a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a></div></blockquote></div><br></div></div></blockquote></div><br></div></body></html>