Hi, John , Mike
Life , sometimes isn't pleasant -- , father drowned in 2006 (and I had to identify him) -- there's more water than land here ....
... March 27th to be exact and it was snowing , .. is that the Vladivostok regio, Mike ??
" more and more possessed by LISP"
héhé
It's such a simple language , just like the "Elements of Euclides" , it is based on almost nothing -- Euclides used the point, the line and the circle, and lisp does list , cons , car , cdr , let , quote , eval
------- another sample --------- AI like
;; NewLISP flavor ;;;
;; code by RobbeK
(define-macro (car x) (first (eval x)))
(define-macro (cdr x) (rest (eval x)))
(define-macro (cadr x) (first (rest (eval x)))) ;; i don't like the modernistic (first ) and (rest )
(define (mono? L)
(apply and (map (curry = (car L)) (cdr L))))
(define (dif* L M)
(if (= (length L) 1) (reverse M)
(dif* (cdr L) (cons (- (cadr L) (car L)) M) )))
(define (dif L) (dif* L '()))
(define (integrate* L M) ;; needs a start value !!!!
(if (null? L) (reverse M)
(integrate* (cdr L) (cons (+ (car L) (car M)) M))))
(define (integrate L startvalue)
(integrate* L (list startvalue)))
(define (analyze L)
(let ((depth 0) (M L) (zo '()) )
(while (and (not (mono? M)) (!= (length M) 1))
(push (car M) zo)
(++ depth)
(setq M (dif M))
)
(if (= 1 (length M)) (println "I'm not clever enough to do such things")
(begin
(println "found a solution at depth " depth)
(println "I'll do a reconstruction ")
(print "Number of elements in the list to expanded : ")
(letn (( nr (integer (read-line)))
( list0 (dup (+ (car M) 0L ) nr)))
(dotimes (i depth t)
(setq list0 (integrate list0 (zo i) ))
)
(println "")
(println "The result is " list0))))))
(define (demo)
(println "This is a demo of differentations / integrations of sequences")
(println "-------------------------------------------------------------")
(println " ")
(println "something simple to start with ")
(let (( s "(analyze (list 1 2 3 4 5 6 7
)"))
(println s)
(println " ")
(eval-string s)
(print "\nSomewhat more difficult : ")
(setq s "(analyze (list 1 4 9 16))")
(println s)
(eval-string s)
(println " ")
(print "\nOK, try this : ")
(setq s "(analyze (list 0 3 8 15))")
(println s)
(eval-string s)
(print "\n")
(println "OK -- humanoid, try this one yourself")
(setq s "(analyze (list 6 25 62 123 214))")
(println s)
(eval-string s)
(println "did you see it ? -- it was x^3 - 2 ")
(print "\n")
(println "However :-( ")
(setq s "(analyze (list 2 3 5 7 11 13))")
(println s)
(eval-string s)
))
(demo)
------------------------------------------
Code differentiates sequences till a list with constant values is reached :
tested with
(define (mono? L)
(apply and (map (curry = (car L)) (cdr L))))
this is almost natural language -- it means the list shows identical numbers when the first number is the same as the rest of the list ... the currying comes from Haskell , but it is easy to write as a macro I think , here it is short for
(lambda (x) (= x (car L)))
When a "mono list" is reached the mechanism is reversed and integration starts -- with the advantage the sequence is expandable to any number of elements ....
however, as you can see in the demo , primes , n! , fibo's etc... will not reveal any working pattern ...
best Rob
there's always music to comfort us
https://www.youtube.com/watch?v=JxPj3GAYYZ0 .. we're not alone !!
.