self explaining lines (or what args can do for you)

Pondering the philosophy behind the language
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

self explaining lines (or what args can do for you)

Post by newdep »

Code: Select all

(define-macro (this:this) (push (context) (args)))

>(this forum topic should explain itself)                               

(this forum topic should explain itself)

Last edited by newdep on Wed Jul 29, 2009 9:42 pm, edited 3 times in total.
-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post 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)

-- (define? (Cornflakes))

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post 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...
-- (define? (Cornflakes))

Elica
Posts: 57
Joined: Wed Feb 13, 2008 6:41 pm

Post 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.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

is that the default behaviour or it it a program?

a difficult program to write?

Elica
Posts: 57
Joined: Wed Feb 13, 2008 6:41 pm

Post 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.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post 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... :)

Elica
Posts: 57
Joined: Wed Feb 13, 2008 6:41 pm

Post 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?

Locked