Author Topic: LeanLisp update  (Read 3965 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
LeanLisp update
« on: August 06, 2014, 01:25:27 AM »
Lisp code test examples in LispishTest1.txt..3

'loop' with 'if/else' clause
Code: [Select]
  ( set d 4 )
  ( set c 0 )
  ( loop
    ( if d
      ( eval
        ( decr d )
        ( incr c )
      )
      ( exit )
    )
  )
  c
  (cr)
« Last Edit: August 07, 2014, 04:20:43 AM by Charles Pegge »

Peter

  • Guest
Re: LeanLisp update
« Reply #1 on: August 06, 2014, 05:04:09 AM »
Code: [Select]
    sys c, d=4
   
    mov  ecx,d
.lp dec  ecx
    inc  c
    cmp  ecx,0 
    jnz  lp
   
    print c
   
    c=0 : d=4
    while d>0
    c +=1
    d -=1
    wend
   
    print c
   

Mike Lobanovsky

  • Guest
Re: LeanLisp update
« Reply #2 on: August 06, 2014, 06:14:06 AM »
This

Code: [Select]
    sys c, d=4

    mov  ecx,d
.lp dec  ecx
    inc  c
    or   ecx,ecx
    jnz  lp

will be tighter (fewer machine code bytes) while this

Code: [Select]
    sys c, d=5
   
    mov  ecx,d
.b  dec  ecx
    jz   f
    inc  c
    jmp  b
.f

should be faster on a Pentium.

Charles Pegge

  • Guest
Re: LeanLisp update
« Reply #3 on: August 06, 2014, 06:54:30 AM »
Another example:

data Selection and extraction:
Code: [Select]
(eval

"Item Ordinal containing: " '"three"' (cr)
  (let s "( AA one ) ( BB two ) ( CC three ) ( DD four ) ( EE five )" )
  (let k "three")
  (let f (find 1 s k) )
  (let p (ordpos s f) )
  ( let t (inner (getmid s p 1) ) )
  "content:        " (get s) (cr)
  "char position:  " f (cr)
  "item ordinal:   " p (cr)               ; 3
  "item extracted: " (getmid s p 1) (cr)  ; ( CC three )
  "item inner:     " t (cr)               ; CC three
  "inner member 2: " (getmid t 2 1 ) (cr) ; three
  (cr)
  "ok" (cr)
)

Charles Pegge

  • Guest
Re: LeanLisp update
« Reply #4 on: August 07, 2014, 04:25:47 AM »
Update with correction to (input)

User input with a simple console loop
Code: [Select]
  (print "Enter Lispish Expressions:" (cr) )
  (loop
  ( do
    (color 0xb)
    (let e (input) )
    (case (get e) "" (exit) )
    (color 0xe)
    (print e (cr) ) ; evaluated
    (color 0x7)
  )
  )
  (cr) 
« Last Edit: August 09, 2014, 02:32:30 AM by Charles Pegge »

Charles Pegge

  • Guest
Re: LeanLisp update
« Reply #5 on: August 07, 2014, 10:58:58 AM »
Using the console loop above:

defining and testing av average:

Enter Lispish Expressions:

( / ( + ) 0 )
#qNAN
(let av "( / ( + (next) item ) (count) ) " )

( av 1 2 3 )
2
( av )
#qNAN
( av 1 )
1
( av 2 3 )
2.5

JRS

  • Guest
Re: LeanLisp update
« Reply #6 on: August 07, 2014, 11:46:28 AM »
Charles,

Could LeanLisp eventually be made a library  (DLL) or a JIT method?

Charles Pegge

  • Guest
Re: LeanLisp update
« Reply #7 on: August 09, 2014, 02:41:06 AM »
Creating a LeanLisp DLL:

Code: [Select]
% Filename "LeanLisp.dll"
% DLL
includepath "$\inc\"
include rtl32.inc
include console.inc
includepath ""
% UseSystemConsole
% NoOxygenCompile
include LispishUtil.inc

extern export

function lispB(string s) as string
==================================
return lisp s
end function

function lispC(char *ib,*ob, sys lb)
====================================
string s=ib
string t=lisp s
sys lt=1+len t
if lt>lb then
  lt=lb : mid t,lt, chr(0)
end if

if @ob then
  copy @ob, strptr t, lt
end if
end function

end extern

Accessing the DLL (Oxygen)
Code: [Select]
extern lib "LeanLisp.dll"
! lispB(string s) as string
! lispC(char*ib,*ob, sys lb)
end extern

'BSTR / OLESTRING INTERFACE
===========================
'string s=lispB getfile "LispishTest3.txt"

'CHAR* INTERFACE
================
sys    lb=0x10000 'length of output buffer ob
string ib=getfile "LispishTest3.txt"
string ob=nuls lb

lispC ib,ob,lb

Test Code: (LispishTest3.txt)
Code: [Select]
(eval
  (print "Enter Lispish Expressions:" (cr) )
  (loop
  ( do
    (color 0xb)
    (let e (input) )
    (case (get e) "" (exit) )
    (color 0xe)
    (print e (cr) ) ; evaluated
    (color 0x7)
  )
  )
  (cr) 
)


32 bit DLL included:


.

Peter

  • Guest
Re: LeanLisp update
« Reply #8 on: August 09, 2014, 04:20:49 AM »
fine stuff !
I  tried a litte bit with  funny results and sometimes I had luck.   :)

Charles Pegge

  • Guest
Re: LeanLisp update
« Reply #9 on: August 14, 2014, 12:35:15 AM »
List of Fibonacci Numbers

Code: [Select]
"lists: fibolist:" (cr)

( let fibolist "c
  ( eval
    ( let t )
    ( let v 1 )
    ( let w 1 )
    1 1
    ( eval
      ( = t w )
      ( = w ( + v  w ) )
      ( = v t )
      w
      ( iter c )
    )
  )
")
( fibolist 10 ) (cr)


lists: fibolist:
1 1 2 3 5 8 13 21 34 55 89 144


Mike Lobanovsky

  • Guest
Re: LeanLisp update
« Reply #10 on: August 14, 2014, 12:59:54 AM »
Hehe,

1. It doesn't look like a recursive algo. Is it an iterative solution?

2. It won't be accepted to RosettaCode as a solution. It doesn't contain a check for the validity of function arguments. ( (> n 1) ) :P

:D

Charles Pegge

  • Guest
Re: LeanLisp update
« Reply #11 on: August 14, 2014, 01:15:39 AM »
Hi Mike,

Parameter c iterates eval by downcount. Iteration continues for values >0.

w values are appended to the eval list.

    ( eval
      ( = t w )
      ( = w ( + v  w ) )
      ( = v t )
      w ; append to list
      ( iter c )
    )
« Last Edit: August 14, 2014, 01:31:55 AM by Charles Pegge »

Charles Pegge

  • Guest
Re: LeanLisp update
« Reply #12 on: August 14, 2014, 04:30:30 AM »
Fibonacci list: Recursive alternative

Code: [Select]
"lists: fibolist recursive:" (cr)
( let a 1 )
( let b 1 )
( let fibolist " a b c
  ( eval
    ( let d ( + a b ) )
    d ; eval output
    ( decr c )
    ( if ( > c 0 )
      ( fibolist b d c ) ; recurse
    )
  )
")
a b ( fibolist 1 1 10 ) (cr)

lists: fibolist:
1 1 2 3 5 8 13 21 34 55 89 144