Homoiconic Lisp Homoiconic Lisp

Homoiconic Lisp Homoiconic Lisp

Homoiconic Lisp Yosuke Fukuda Graduate School of Informatics, Kyoto University The goal of this work and the current status The notion of “Homoiconicity” •Ultimate goal To give a reasonably minimal condition of “program se- According to Alan Kay [Kay 1969], a language is mantics” to define various program semantics called homoiconic if its internal and external rep- •Current status A Lisp implementation that can define a lot of program- resentations are essentially the same. ming language features for it, in the language itself Homoiconic Lisp (HLisp) Feature GitHub Repository •HLisp is a small fragment of Scheme with a first class macro mechanism The implementation of Homoiconic Lisp is available at •It can write a lot of constructs (e.g. if-expression, recursive function https://github.com/yf-fyf/hlisp definition, and quasi-quotation) as user-defined programs •It is based on a simple extension of SECD machine [Landin 1964] with a few primitives Macro closure, a way to achieve homoiconicity The notion of macro closure is a function closure to manipulate program, designed analogously to the closure of λ-abstraction Intuition of its computation ((macro (x1 ··· xn) M) N1 ··· Nn) (eval M[x1 := (quote N1); ··· ; xn := (quote Nn)]) Example The first program shows a usage of macro closure (macro abstraction), that corresponds to the secondone 1 ((macro (x y) x) (print 123) (print 456)) 1 (eval ((lambda (x y) x) '(print 123) '(print 456))) 2 ; => 123 (as a side-effect) 2 ; => 123 (as a side-effect) An extended SECD machine with macro closure, ESECD Syntactic category Constant c ::= f j f j quote j eval Stack S ::= nil j U :: S Term M; N ::= c j x j λx:M j λx:M j @MN j dMe Environment E ::= nil j hx; Ui :: E SECD Value U ::= c j h(λx:M); Ei j h(λx:M); Ei j dMe Control string C ::= ret j back j call :: C j M :: C Dump D ::= halt j hS; E; C; Di j hM; C; Di Transition rules (with some omissions) Example (λx:1) (print 0) + 1 (without any printing effect) h ; ; ( (λ :1) ( 0)) :: ; i hS; E; c :: C; Di hc :: S; E; C; Di S E @ x print ret halt hS; E; x :: C; Di hU :: S; E; C; Di if U = Lookupx(E) hS; E; (λx:1) :: back; h(print 0); ret; haltii hS; E; (λx:M) :: C; Di hh(λx:M); Ei :: S; E; C; Di hh(λx:1); Ei :: S; E; back; h(print 0); ret; haltii hS; E; (λx:M) :: C; Di hh(λx:M); Ei :: S; E; C; Di hdprint 0e :: h(λx:1); Ei :: S; E; call :: ret; halti hS; E; (@MN) :: C; Di hS; E; M :: back; hN; C; Dii hnil; hx; dprint 0ei :: E; 1 :: ret; heval :: S; E; call :: ret; haltii 0 0 0 0 hhλx:M ; E i :: S; E; back; hN; C; Dii hhλx:M ; E i :: S; E; N :: call :: C; Di h1 :: nil; hx; dprint 0ei :: E; ret; heval :: S; E; call :: ret; haltii 0 0 0 0 hhλx:M ; E i :: S; E; back; hN; C; Dii hdNe :: hλx:M ; E i :: S; E; call :: C; Di h1 :: eval :: S; E; call :: ret; halti 0 0 0 0 hU :: h(λx:M ); E i :: S; E; call :: C; Di hnil; hx; Ui :: E ; M :: ret; hS; E; C; Dii h1 :: S; E; ret; halti 0 0 0 0 0 hdNe :: h(λx:M ); E i :: S; E; call :: C; Di hnil; hx; dNei :: E ; M :: ret; D i hU :: quote :: S; E; call :: C; Di hU :: S; E; C; Di hdMe :: eval :: S; E; call :: C; Di hS; E; M :: C; Di hU :: eval :: S; E; call :: C; Di hU :: S; E; C; Di if U is not a code 0 0 0 0 0 0 0 0 hU :: S; E; ret; hS ; E ; C ; D ii hU :: S ; E ; C ; D i Property of ESCD Future work The “correctness” of ESCD is shown through a λ-calc. as in [Plotkin 1975] •Fill the gap between ESECD and HLisp, since the Thm If M is a closed term, then TFAE: former has no primitive that produces side-effect •M + V in λH (Note: λH is an extension of λ-calc. with macro closure) •Extend the theory and implementation to cover •hnil; nil; M :: ret; halti + U in ESECD other evaluation strategies (Adding a hook oper- where V and U denote the “same” value (formally, defined as in [Plotkin 1975]) ation to variable lookup may achieve this) LATEX TikZposter.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    1 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us