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

Started by newdep, July 29, 2009, 02:36:49 PM

Previous topic - Next topic

newdep


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

>(this forum topic should explain itself)                              

(this forum topic should explain itself)

-- (define? (Cornflakes))

newdep

#1
another one (dont be fooled ;-)




(define (return:return) (clean nil? (args)))

> (return any number from 10 upto 100 from this line)

(10 100)

-- (define? (Cornflakes))

newdep

#2
another fool in the pool..




> (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

#3
If Lisp were not stuck with the prefix-only notation, it would be possible to recreate the following toy-program:


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

#4
is that the default behaviour or it it a program?



a difficult program to write?

Elica

#5
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

#6
It's not totally beyond the capabilities of newLISP, you know:


(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:


> 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

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