Skip to content
yesco edited this page Feb 29, 2016 · 46 revisions

esp-lisp documentation

Esp-lisp is mostly try to be scheme-ish, at least for functions defined. It is, however, limited and small, not trying to contain all functions.

functions

  • t nil null? atom? symbol?
  • cons car cdr set-car! set-cdr! cons?
  • list assoc length member map mapcar
  • de define set! quote lambda progn func?
  • length string? (strings)
  • < = eq equal (compare)
  • if cond and or not
        • / % number? integer?
  • read princ prin1 print terpri printf (read and write)
  • eval evallist apply
  • gc test syms (internal)
  • clock ticks time (system)
  • in out (digital pin IO)
  • web wget (web stuf)
  • at stop atrun (event timers)

commands

  • help = give some help: list some symbols, and commands
  • trace on / trace off = turns eval tracing on or off
  • gc on / gc off = turn gc tracing on or off
  • bye / quit / exit / ^D = leave esp-lisp

define function

Currently, esp-lisp has no specific de/defun/define syntax, so just use:

lisp> (define plus (lambda (a b) (+ a b)))
#func[]
lisp> (plus 3 4)
7

lexical

lisp> (define a 9)
9
lisp> (define topa (lambda () a))
#func[]
lisp> (topa)
9
lisp> (set! a 111)
111
lisp> a
111
lisp> (topa)
111
lisp> ((lambda (a) (+ a (topa))) 777)
888

real closures

lisp> (define mkints (lambda (b) (lambda ()(set! b (+ b 1))))))
#func[]
lisp> (define next-int (mkints 5))
#func[]
lisp> (next-int)
6
lisp> (next-int)
7

eval with "custom" environment

lisp> (define a 3)
3
lisp> (eval (quote a) (cons (cons (quote a) 5)))
5
lisp> (env)
((a . 3) (fibo . #func[]) (nil) ...

time related functions

Ticks increase in idle state each time the idle function is called. Also, calling the ticks function increase it. Thus, the difference will at be one. It's monotonically increasing, but not regularly.

lisp> (ticks)
69589278
lisp> (- (ticks) (ticks))
1

Clock returns time since process start in ms.

lisp> (clock)
163119

Time the difference in clock time ms for producing the result. Result it (clock-time . result).

lisp> (time (fibo 22))
(135 . 28657)
lisp> (time (fibo 22))
(136 . 28657)

Web related functions

To get a web page:

lisp> (define whandler (lambda (a b c) (princ a) (if b (princ b)) (if c (princ c))))
lisp> (wget "yesco.org" "http://yesco.org/index.html" whandler)

To serve web pages:

lisp> (web 8080 (lambda (what method path) (if what nil "string to return"))))

ESP8266 I/O

Read value from GPIO-0

lisp> (in 0)
1

Write value to GPIO-5

lisp> (out 5 1)
1
lisp> (out 5 0)
0

schedule idle tasks

The idle function has been augumented with a simple background task manager, it'll run a task 1000 ms in the future.

lisp> (at 1000 (lambda () (princ "ONE TIME")))
(4711 1000 . #func)
lisp> and while we areONE TIME typing

repeating tasks

A task can be made repeating by using a negative number, it is then rescheduled after being run, in this case, at 1000 ms in the future, repeadetly, until explicitly cancelled.

lisp> (at -1000 (lambda () (princ ".")))
(61000 -1000 . #func)
lisp> (at -3000 (lambda () (princ "THREE")))
(63000 -3000 . #func)
lisp> ...THREE...THREE...THREE...THREE

cancel a task

lisp> (define never (at 1000 (lambda () (princ "NEVER"))))
(72000 1000 . #func)
lisp> (stop never)
*stop*
lisp>
Clone this wiki locally