alexharsanyi
2021-10-23 09:10:56

chansey97
2021-10-23 15:04:15

An accidental discovery: procedures in Emacs-lisp are transparent. (eval '(let ((x 1))      (lambda () (+ x 1))) t) ;; (closure ((x . 1) t) nil (+ x 1)) Although this (closure ...) is a list, it can be invoked directly. ((closure ((x . 1) t) nil (+ x 1))) ;; 2 IMO, it looks more consistent than Racket. Since Racket has transparent struct, why no transparent procedure? It would be nice if we could have both transparent and opaque procedure, just like struct!

Further investigation, about sharing: (setq print-circle t) (eval '(letrec ((f (lambda (x) (if (&gt; x 0) 0 1))))      f) t) ;; #1=(closure ((f . #1#) t) (x) (if (&gt; x 0) 0 1)) As you can see, when using (setq print-circle t), emacs prints the cyclic structure. Unfortunately, it can not be read by emacs directly, because emacs-lisp does not support <https://docs.racket-lang.org/reference/reader.html#(part._parse-graph)|Reading Graph Structure> like Racket.


soegaard2
2021-10-23 15:10:24

At minimum each closure would need to have an extra slot containing information on the variable names. Allocating a transparent closure would therefore take more time. This explains why transparent closures aren’t the default in many languages.

In Racket you can use

https://docs.racket-lang.org/web-server-internal/closure.html

to experiment with transparent (aka serializable) closures.


soegaard2
2021-10-23 15:10:56


soegaard2
2021-10-23 15:12:29

The last paper shows in section 2.2 that a closure might not contain all free variables.


chansey97
2021-10-23 15:56:30

@soegaard2 Thanks. I just tried define-closure, it’s nice, but the serialized form are not readable as the emacs one. > Allocating a transparent closure would therefore take more time. Is it possible to maintain an additional transparent representation just for reification? In general, we do not allocate a lot of closures continuously.


soegaard2
2021-10-23 16:21:58

I think, it would be relatively simple to change the printing.


soegaard2
2021-10-23 16:52:53

I have chosen to use React with hooks. I like the functional feel of it. I am not using jsx though. I wanted to generate the final JavaScript directly from Urlang without any external tools, so I use a macro that generates the same output as jsx does (but with a different input syntax).

Apropos, React with hooks. There is a new set of documentation: https://beta.reactjs.org/learn


ben.knoble
2021-10-23 16:53:24

Would love to see that macro :heart_eyes:


soegaard2
2021-10-23 16:54:36

soegaard2
2021-10-23 16:55:37

I can wrote stuff like: (define (ExerciseAnswerInput props) (def (on-change e) (props.set-user-answer e.target.value)) @urx[@Form[@InputGroup[ @InputGroup.Prepend[ @InputGroup.Text[@ur[(result-type-&gt;text props.result-type)]]] @Form.Control[placeholder: "Svar" onChange: on-change onKeyUp: props.onKeyUp onKeyDown: props.onKeyDown type: "text" ref: props.input-ref disabled: props.disabled tabIndex: 0]] @Form.Text[className: "text-muted" @ur[props.error-message]]]])


ben.knoble
2021-10-23 17:00:47

That’s awesome. Not sure why anyone would write JS by hand anymore :slightly_smiling_face:


a11ce
2021-10-23 20:38:36

laurent.orseau
2021-10-23 20:51:45

(define 1+1 (+ 1 1)) :stuck_out_tongue:


jcoo092
2021-10-24 03:58:30

I can hear Fry’s voice narrating the very start of Futurama as I watch :smile:


chansey97
2021-10-24 04:23:45

@soegaard2 But this gives me the feeling that it is not “built-in”, because it needs some intermediate structure to do the conversion. Ideally, the printed result can be used (or invoked) directly in a program, like (closure ...) in emacs-lisp.

For example, (struct my-struct (x y) #:transparent) (my-struct 1 2) ;; =&gt; (my-struct 1 2) The printed result (my-struct 1 2) could be used in a Racket program directly. It expresses some homoiconicity of lisp.


chansey97
2021-10-24 04:31:35

Ideally, serialization and deserialization should not appear in lisp, unless performance or space consumption was concerned.