[gambit-list] -target js

Francois Magnan magnan at categoricaldesign.com
Thu Nov 21 11:01:49 EST 2013


Hi,

Sorry to disturb you again on this. I continued my experiments with “-target js”. I reimplemented quasiquote, unquote… and I stumbled on a strange bug that mystifies me: now “cons” function is not known. I have sucessfully compiled programs using cons with -target js many times but now it just won’t compile it correctly. Here is a simplified version of the code just to illustrate what I see:


; File:  Minimal-Ex1.scm


(declare (standard-bindings)
         (extended-bindings)
         (fixnum) (not safe))


; include Marc's code 
(include "obj2str.scm")


;;;
;;;; debugging utility
;;;


(define (console.log x)
  ;; Note: the parameter x will be in variable Gambit_r1
  (##inline-host-statement "console.log(Gambit_r1.toString());\n"))


;;;
;;;; list utilities I had to redefine
;;;


(define (myreverse l)
  (define (iter a b)
    (if (null? a) b
      (iter (cdr a) (cons (car a) b))))
  (iter l (list)))


(define (iota n)
  (myreverse (riota n)))


(define (riota n)
  (if (= n 0) 
      (cons 0 '())
    (cons n (riota (- n 1)))))


(define (foldl func accum lst)
  (if (null? lst)
      accum
      (foldl func (func accum (car lst)) (cdr lst))))


(define (foldr func end lst)
  (if (null? lst)
      end
      (func (car lst) (foldr func end (cdr lst)))))


(define (appendo . lists)
	(foldl append2 '() lists))


(define (append2 l1 l2)	
  (foldr cons l2 l1))


(console.log (object->string (cons 1 2)))   ; OK   (1 . 2) 
(console.log (object->string (iota 5)))     ; OK   (0 1 2 3 4 5)
(console.log (object->string (append2 (list 1 2 3) (list 'a 'b 'c))))  ; FAILS [Error] ReferenceError: Can't find variable: Gambit_bb1_cons

—————————————————————————————————————-
magnan$ gsc -c -target js  Minimal-Ex1.scm
magnan$ node Minimal-Ex1.js 
(1 . 2)
(0 1 2 3 4 5)

/Users/magnan/CDSCode/CDSProducts/Athena-Embedded/src/Athena-Embedded/Minimal-Ex1.js:5551
  Gambit_r1 = (Gambit_bb1_cons);
               ^
ReferenceError: Gambit_bb1_cons is not defined

You see that (cons 1 2) and (iota 5) compiles well but not (append2 … ). 
Can you explain this?

Thank you,
Francois Magnan


On 2013-11-18, at 16:02, Francois Magnan <magnan at categoricaldesign.com> wrote:

> Hi Marc,
> 
> I was finally able to make a simplified version my program work when compiled to javascript but I am missing some crucial elements to complete the experiment:
> 
> 1 - Variable number of parameters for functions: (define (function . args) …)
> 2 - Quasiquote, unquote and unquote-splicing
> 
> Without 1) I cannot get functions like “append” so I have a hard time trying to solve 2). 
> Can you give me hints for that or drop me an email when those features become available with the “-target js” option?
> 
> Thank you,
> François
> 
> 
> 
> 
> 
> On 2013-11-14, at 17:06, Marc Feeley <feeley at iro.umontreal.ca> wrote:
> 
>> 
>> On Nov 14, 2013, at 4:23 PM, Francois Magnan <magnan at categoricaldesign.com> wrote:
>> 
>>> By the way ##inline-host-code doesn’t seem to work anymore.
>>> 
>>> (define (console.log x)
>>> ;; Note: the parameter x will be in variable Gambit_r1
>>> (##inline-host-code “console.log(Gambit_r1);\n”))
>>> 
>>> How can I inline javascript code now?
>>> Thank you,
>>> Francois
>>> 
>> 
>> Recall that ##inline-host-code no longer exists... you have to use ##inline-host-statement and ##inline-host-expression depending on the nature of the code.  For example, this works for me using node:
>> 
>> (declare (extended-bindings) (not safe))
>> 
>> (define (show arg)
>> (##inline-host-statement "console.log(Gambit_r1.toString());"))
>> 
>> (show 'hello)
>> 
>> (show "world")
>> 
>> (show (##inline-host-expression "1+2+3"))
>> 
>> Marc
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20131121/5d4e74fa/attachment.htm>


More information about the Gambit-list mailing list