git » jacl.git » master » tree

[master] / notes.txt

(use-package :js)

; jacl:js
; jacl:dot
; jacl:to-js
; jacl:\.

; js:enable-js-syntax (for @"js strings")
; js:+null+
; js:+true+
; js:+false+
; js:+undefined+
; js:\.

; global reference
; JS: window
(global |window|)
window

; field access
: JS: window.location
(dot window |location|)

(let ((win window))
  (dot win |location|))

; method call
; JS: window.alert("hello!")
((dot window |alert|) (js-string "hello!")

; add JS string literals like @"foo" (equivalent to (js-string "foo"))
(eval-when (:compile-toplevel :load-toplevel :execute)
  (enable-js-syntax))

; sugared method call
(\. window (alert @"hello!"))



((dot (global |window|) |alert|)
 ((dot "hello, world!" |toString|)))

((dot (global |window|) |alert|)
 (to-js "hello, world!"))

;; factorial
(%js "(~{}.fvalue = ~{})"
  'fact
  (%lambda (n &aux (prod 1))
    (%tagbody
      t0
      (%if (!eql n 0) (%go done) nil)
      (%set-var prod (!* prod n))
      (%set-var n (!- n 1))
      (%go t0)
      done)
    prod))

(%let ((x 0))
  (%tagbody
    t0
    (%if (> x 10) (%go t1) nil)
    (!log x)
    (%set-var x (+ x 1))
    (%go t0)
    t1
    (!log "done"))
  0)

;; interop todo

;;%FUNCTION
%OBJECT
%ARRAY
%AREF
%NEW