YaK:: Twerp -- LTwerp -- a minimalistish Pure Lisp interpreter, in C++ [Changes]   [Calendar]   [Search]   [Index]   [PhotoTags]   
[mega_changes]
[photos]

Twerp -- LTwerp -- a minimalistish Pure Lisp interpreter, in C++

NEW LOCATION:

The code is now in a darcs repository at http://albus.yak.net/repos/ltwerp/ or you can get a snapshot with wget -m -nv -np http://albus.yak.net/repos/ltwerp/

./a.out [012]*.l "(list (let chr (lambda (n) (if (null n) '@ (succ (chr (sub1 n))))) (implode (mapcar (mapcar '(XVIIII XX XVIII VIIII III XI) peano) chr))))" 2>&1 | tail -1
or, with the Y combinator:
./a.out [0123]*.l "(list (run (implode (mapcar (mapcar '(XVIIII XX XVIII VIIII III XI) peano) (Y (lambda (self) (lambda (n) (if (null n) '@ (succ (self (sub1 n))))))) )) ))" 2>&1 | tail -1

THE FOLLOWING HAS NOT BEEN UPDATED and is probably somewhat obsolete.

/file lterp-2009-01-19.cc

Usage: a.out lib1.lt lib2.lt ... "(call-some-function)" -- Command line arguments are either lisp source files or, if an argument starts with "(", an expressionn to eval. In the latter case, if the result is an atom, its print value is sent to stdout, raw; but if the result is a list, it is printed to stdout with normal formatting and escaping. Compile with -D"NDEBUG" to supress lots of debugging output to stderr.

(let atom1 expr1 atom2 expr2... resultExpr) -- evals expr1 and binds to atom1; then expr2 to atom2, etc.; finally evals resultExpr and returns it. (We omit 2 layers of parentheses around the atom/expr pairs, from the normal LET syntax).

(defun name (arg1 arg2...) expr) -- defines the name as global variable to have lambda expression

(call-cc f) -- calls f, passing it the Current Continuation, such that when the continuation is used later as a function, passing it some value x, the flow of control jumps back to the invokation of call-cc, which then returns x. See return.lt for an example.

TODO

INTERNALS

Updates

strick@retro:~/lterp$ ./lterp   lib.lt    macro.lt  "(incr-fn '5)"
      [12] eval:
        == x<139386416>
      [11] eval:
        == +
      [10] apply:
        ++ +  ==>  <EVAL#11>  <==
        ++ x<139386416>  ==>  <EVAL#12>  <==
        ++ n<139264920>  ==>  5  <==
      [9] unbind:
        -- n<139264920>  ==>  5  <==
      [8] unbind:
        -- ___FRAME___  ==>  ( lambda ( n<139264920> ) ( + x<139386416> n<139264920> ) )  <==
      [7] eval:
        == ( x<139386416> )
      [6] eval:
        == lambda
      [5] eval:
        == list
      [4] apply:
        ++ list  ==>  <EVAL#5>  <==
        ++ lambda  ==>  <EVAL#6>  <==
        ++ ( x<139386416> )  ==>  <EVAL#7>  <==
        ++ ( ( lambda ( n<139264920> ) ( + x<139386416> n<139264920> ) ) n<139264920> )  ==>  <APPLY#10>  <==
      [3] unbind:
        -- n<139264920>  ==>  5  <==
      [2] unbind:
        -- ___FRAME___  ==>  ( lambda ( n<139264920> ) ( list lambda ( x<139386416> ) ( ( lambda ( n<139264920> ) ( + x<139386416> n<139264920> ) ) n<139264920> ) ) )  <==
      [1] unbind:
        -- ___FRAME___  ==>  ( incr-fn '5 )  <==
      [0] Result: <APPLY#4>
LOOKUP NOT FOUND: x<139386416>

  • lterp-2009-01-27.cc

    Demonstrating Church Integers

    (based on test code in ParentheTcl -> http://albus.yak.net/repos/parenthetcl/tests/church.p7 )
    strick@retro:~/lterp$ cat church.lt
    
    (fn  '0
         '(f)
         (lambda (x) x))
    
    (fn  '1
         '(f)
         (lambda (x) (f x)))
    
    
    (fn  '2
         '(f)
         (lambda (x) (f (f x))))
    
    (fn  '++
         '(n)
         (lambda (f) (lambda (x) (f ((n f) x)))))
    
    (def '3 (++ 2))
    (def '4 (++ 3))
    (def '5 (++ 4))
    
    (fn  'tick
         '(s)
         '(implode (list 'I s)))
    
    (say (list '0-> ((0 tick) '.)))
    (say (list '1-> ((1 tick) '.)))
    (say (list '2-> ((2 tick) '.)))
    (say (list '3-> ((3 tick) '.)))
    (say (list '4-> ((4 tick) '.)))
    (say (list '5-> ((5 tick) '.)))
    
    
    ; composition is multiplication
    
    (fn 'compose/curry
        '(f)
        (lambda (g) (lambda (x) (f (g x)))))
    
    (fn 'times '(a b) '((compose/curry a) b))
    
    (def '12 (times 3 4))
    
    (say (list '12-> ((12 tick) '.)))
    
    strick@retro:~/lterp$ ./lterp lib.lt macro.lt  church.lt
    ## ( 0-> . )
    ## ( 1-> I. )
    ## ( 2-> II. )
    ## ( 3-> III. )
    ## ( 4-> IIII. )
    ## ( 5-> IIIII. )
    ## ( 12-> IIIIIIIIIIII. )
    strick@retro:~/lterp$
    
  • church.lt
  • twerp.h
  • twerp.cc
  • (unless otherwise marked) Copyright 2002-2014 YakPeople. All rights reserved.
    (last modified 2009-02-26)       [Login]
    (No back references.)