Code Monkey home page Code Monkey logo

robert-van-engelen / lisp Goto Github PK

View Code? Open in Web Editor NEW
67.0 67.0 4.0 232 KB

A mini Lisp in 1k lines of C with garbage collector, explained. Includes over 40 built-in Lisp primitives, floating point, strings, closures with lexical scope, macros, proper tail recursion, exceptions, execution tracing, file loading, a mark-sweep/compacting garbage collector and REPL.

License: BSD 3-Clause "New" or "Revised" License

NewLisp 4.49% C 71.58% C++ 23.87% Shell 0.05%
c cpp garbage-collection lisp lisp-interpreter mark-and-compact mark-and-sweep

lisp's People

Contributors

robert-van-engelen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lisp's Issues

nested define: ERR out

I tried this: nested define:

rs.lisp:

; if these defines are not nested, it works.
; (define take (lambda (n seq) (if (<= n 0) (quote ()) (cons (car seq) (take (- n 1) (cdr seq))))))
; (define drop (lambda (n seq) (if (<= n 0) seq (drop (- n 1) (cdr seq)))))
; (define mid (lambda (seq) (/ (length seq) 2)))

(define combine (lambda (f)
        (lambda (x y)
          (if (null? x) (quote ())
              (f (list (car x) (car y))
                 ((combine f) (cdr x) (cdr y)))))))

; but not inside:
(define riff-shuffle (lambda (deck) (begin
      (define take (lambda (n seq) (if (<= n 0) (quote ()) (cons (car seq) (take (- n 1) (cdr seq))))))
      (define drop (lambda (n seq) (if (<= n 0) seq (drop (- n 1) (cdr seq)))))
      (define mid (lambda (seq) (/ (length seq) 2)))
      ((combine append) (take (mid deck) deck) (drop (mid deck) deck)))))

(riff-shuffle (list 1 2 3 4 5 6 7 8))

unbound take ERR 3 unbound symbol:

6322+1929>(load "rs.lisp")
(load "rs.lisp")
combine
riff-shuffle
unbound take ERR 3 unbound symbol

6024+1921>(riff-shuffle (list 1 2 3 4 5 6 7 8))
unbound take ERR 3 unbound symbol

the correct output should be:

> (load "rs.lisp")
> (riff-shuffle (list 1 2 3 4 5 6 7 8))
(1 5 2 6 3 7 4 8)

Problem with a macro

Is there any reason why the following macro raises an error:
(define ++ (macro (x) (list 'setq x (list '+ x 1))))
It is ment to act like the C function '++'. The error text is: unbound symbol. The symbol appears to be the '+

Wrong read() silently linked when using readline

I’ve encountered a problem leading to infinite recursion because the wrong ‘int read()’ function is being linked (silently) when using readline. I’ve verified this happens on two distinct systems (Redhat Linux, Alpine Linux). The solution is to rename the read() symbol in lisp.c to lread() or anything other than read().

Apply function?

An interesting way to specify a while loop is the following:

(define while (lambda (body . args)
(apply body body args)))
(while (lambda (loop i)
(if (not (eq? i 0))
(begin
(print i)
(loop loop (- i 1)))
'done)) 5)

It should print '54321done'. In your lisp implementation all needed functions are available, except 'apply'. Actually this function is used in a lot of other clever lisp examples, and it cannot be written as a macro. Do you think you can create it in your program?

Calling C example + printf wrapper

Hello,

What a wonderful lisp implementation, good job. Can you please add at least one example of how to call a new C defined function from lisp? (I am new to Lisp so maybe I missed it in the readme).

As it is a good candidate for many embedded platforms (microcontrollers), maybe it could be worth to wrap the (f)printf functions so that theses ones are defined on the host side rather than in the library.

Thank you!

Unexpected behavior of cond

(cond (() 42)) errors with ERR 1 not a pair, whereas I would expect it to evaluate to ().

(if () 42) evaluates to (), as I would expect.

I'm not sure if this is a bug in cond or if I'm misunderstanding how it's supposed to work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.