sasagawa888 / eisl

ISLisp interpreter/compiler
Other
288 stars 24 forks source link

running #326

Closed kwccoin closed 1 month ago

kwccoin commented 1 month ago

Try to follow the example of lambda

` % eisl Easy-ISLisp Ver5.35

(load "lambda.lsp") T (repl) Lambda calculus interpreter To quit enter 'end' L> ^x.x ^x.x ^x.x L> (^x.x)(^y.y) (^x.x)(^y.y) ^y.y ^y.y L> I = ^x.x "syntax error" NIL

Not sure why?

sasagawa888 commented 1 month ago

I wrote the lambda calculus interpreter quite a while ago. I've completely forgotten how it works. Could there be a bug? I'll look into it.

sasagawa888 commented 1 month ago

It doesn't seem like a bug. S, K, I, and Y are combinators. The corresponding lambda expressions are registered in advance. For example, when SKI is executed, it is reduced to a simple lambda expression. Y is a fixed-point combinator. Lambda calculus repeatedly performs substitution operations, applying them over and over until they can no longer be simplified. The interpreter shows this process.

L> SKI
(^x.^y.^z.xz(yz))(^x.^y.x)(^x.x)
(^x.^y.^z.xz(yz))(^x.^y.x)
^y.^z.(^x.^y.x)z(yz)
^z.(^x.^y.x)z(yz)
(^x.^y.x)z(yz)
(^x.^y.x)z
^y.z
^z.z
L> 
kwccoin commented 1 month ago

Look like my newbie usage problem. Thought it is part of user interface. Need to learn how to “register in advance” and how. Can it be done in the interactive shell?

kwccoin commented 1 month ago

Assume not, as seen in the code in the lambda.lsp:


(defpattern combinator
  ((empty) nil)
  ((_x) (when (lambda-p _x)) _x)
  ((I) (parse* "^x.x"))
  ((K) (parse* "^x.^y.x"))
  ((S) (parse* "^x.^y.^z.xz(yz)"))
  ((Y) (parse* "^y.(^x.y(xx))(^x.y(xx))"))
  (((_x :rest _xs)) (cons (combinator _x) (combinator _xs)))
  ((_x) _x))

unless one can safely change this definition?

sasagawa888 commented 1 month ago

defpattern is a unique extension feature of EISL. Generally, in Lisp, you use defun to register functions. You can input (defun foo (x) (+ x 1)) to the interpreter. As a result, the function foo will be registered. (foo 1) will return 2.