Page 1 of 1
self explaining lines (or what args can do for you)
Posted: Wed Jul 29, 2009 9:36 pm
by newdep
Code: Select all
(define-macro (this:this) (push (context) (args)))
>(this forum topic should explain itself)
(this forum topic should explain itself)
Posted: Wed Jul 29, 2009 9:37 pm
by newdep
another one (dont be fooled ;-)
Code: Select all
(define (return:return) (clean nil? (args)))
> (return any number from 10 upto 100 from this line)
(10 100)
Posted: Wed Jul 29, 2009 10:53 pm
by newdep
another fool in the pool..
Code: Select all
> (define (it:it) (silent (define (isn) (set 't "Yes it is!"))))
>(it is nice weather?)
> (isn't it?)
"Yes it is!"
If only silent wouldnt need a press-key...
Posted: Mon Aug 03, 2009 4:34 pm
by Elica
If Lisp were not stuck with the prefix-only notation, it would be possible to recreate the following toy-program:
Code: Select all
mike is tall
john is tall
peter is old
john is old
what is john ; => john is tall and old
john is smart
what is john ; => john is tall, old and smart
who is smart ; => john is smart
who is old ; => peter and john are old
mike is old
who is old ; => peter, john and mike are old
Yes, the text in the example is the real program, the results are shown after the "=>" signs.
The trick is that "x IS y" is a binary operator, which does this:
if x=WHO then search for all nodes which point to y
if x=WHAT then search for all nodes which are pointed to by y
otherwise add a new rule that node x points to node y
FYI: this example is taken from the Elica Museum.
Posted: Mon Aug 03, 2009 7:03 pm
by cormullion
is that the default behaviour or it it a program?
a difficult program to write?
Posted: Mon Aug 03, 2009 7:54 pm
by Elica
It is a 20-30 lines long program which defines IS in a way that simple sentences like "x IS y" are valid programming commands.
Posted: Tue Aug 04, 2009 5:26 pm
by cormullion
It's not totally beyond the capabilities of newLISP, you know:
Code: Select all
(define (show l)
(map (fn (f)
(println (format {%s is %s} (map string (select (facts f) '(0 2)))))) l))
(define-macro (is a b)
(cond
((= a 'who) (show (ref-all (list '? b) facts match)))
((= a 'what) (show (ref-all (list b '?) facts match)))
(true (push (list (sym a) (sym b)) facts))))
(command-event (fn (s)
(if (find "is " s)
(string {(is } (replace {is } s {}) {)})
s)))
then typing in the console:
Code: Select all
> mike is tall
> john is tall
> peter is old
> john is old
> what is john
john is old
john is tall
> john is smart
> what is john
john is smart
john is old
john is tall
> who is smart
john is smart
> who is old
john is old
peter is old
> mike is old
> who is old
mike is old
john is old
peter is old
>
yes, I know the output isn't quite right. I just couldn't be bothered to do any more... :)
Posted: Tue Aug 04, 2009 6:34 pm
by Elica
This looks like a preprocessor inside of an event handler. So, practically, your code treats "x IS y" as data and processes it into something more digestible. Will this work if the commands are inside a text file mixed up with other lisp commands?