Author Topic: Lisp in Basic  (Read 208219 times)

0 Members and 5 Guests are viewing this topic.

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #780 on: September 15, 2014, 06:25:23 AM »
Hi Mike,

I have to translate it into CL first, I'm not very familiar with Scheme macro's -  more later !!


best Rob

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #781 on: September 15, 2014, 10:41:50 AM »
No problem, Rob, forget it then. I will do it myself, it will just take some more time for trial and error. :)

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #782 on: September 15, 2014, 12:08:16 PM »
Hi Mike,

Macro's in Scheme have the reputation to be more difficult to write than in CL (and NewLisp) ...

Voted as the best introduction :  chapter 36/37 of attached (forgot where I downloaded it).

(36.3 describes the loop macro)

best Rob

.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #783 on: September 15, 2014, 04:31:28 PM »
Thanks Rob,

This info will be helpful in my work.

But no, 36.3 does not describe a loop macro. It describes a user defined for macro based on the loop procedure available in some LISP dialects that are irrelevant to me. There is no loop procedure defined in Scheme, there is only do. :)

For anyone who cares, here's a .CHM file on the Scheme language as per R5RS Standard. I find .CHM help much handier than all sorts of modernistic PDF et al. which you can't bind to, or call properly from, your compiled programs.

.

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #784 on: September 16, 2014, 01:12:27 AM »
Hi  Mike , 

Thanks for the CHM :


"But no, 36.3 does not describe a loop macro"  ...  are you sure ?? 

(local ([define high-value hhighi]
   [define loop (lambda (hvari)
      (if (> hvari high-value)
                   ’ done
               (begin
                 hbodiesi ···
                       (loop (+ hvari 1 )))))])
                     (loop hlowi)) ) ]))



mm, this should work without writing  a macro ???  , the argument of a function can be a function , not ? -- there's one problem ..    ..  ...

CHM , is there a way to convert those old HLP files into one ,   my Win7 refuses to read these, even after an update from MS that should fix these

best, Rob

addendum : very rudimentary in NewLISP :

(define (add2 x) (+ x 2))   ;; just an example

(define (loop fun it value)
   (if (zero? it) value
     (loop fun (- it 1) (fun value))))

--------------------------------------------------------------from the REPL
> (loop add2 3 0)
6

> (loop (lambda (x) (* x x)) 4 2)
65536

;;; currying

> (loop (curry * 2) 5 3)
96
« Last Edit: September 16, 2014, 02:07:30 AM by RobbeK »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #785 on: September 16, 2014, 05:28:13 AM »
Hi Rob,

Download and install MS HTML Help Workshop -- it should have a menu option "Decompile..." that can decompile both old .HLP and new .CHM files into constituent parts of a Help Workshop project. Create a new .HHP project and add the decompiled parts to it through a wizard. Finally recompile this new project as a .CHM file. Profit! :)

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #786 on: September 16, 2014, 05:49:19 AM »
Thanks Mike,    (need those old hlp files  :)

this should work in Newlisp (only one macro needed )

(define (add2 x) (+ x 2))

(define (loop fun it value)
   (if (zero? it) value
     (loop fun (- it 1) (fun value))))

;;      ------------------------------------------------------  only now defining the macro

(define-macro (lp from x to y fun)
   (loop (eval fun) (eval (- y x -1)) (eval x)))

(not sure in Scheme, but both from and to should eval to nil and not halt the code giving an error - that me be important , in NewLISP everything undeclared evaluates to nil ......  (or maybe not, the macro doesn't use these -- again not sure this can be compiled (?)

> (lp from 1 to 4 add2)
9

best Rob

putting things together .......  using the loop function as a local

(define-macro (from x to y fun)
  (let ((loop (lambda (fun it value)
            (if (zero? it)  value
               (loop fun (- it 1) (fun value))))))
  (loop (eval fun) (eval (- y x -1)) (eval x))))

> (from 1 to 5 add2)  ;; from recursion  -- if your prog does tail optimizing , most problems should be solved ?
11

 ;)
« Last Edit: September 16, 2014, 06:32:46 AM by RobbeK »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #787 on: September 16, 2014, 10:25:51 AM »
It barely does anything at all yet except some fixnum maths. There will be a very long road full of manual conversion from Petite Chez (whatever this abracadabra means) to C and assembly. But when the work is over, it will have do and named let, fixnums and flonums, chars, strings and vectors, macros, optimized tail recursion, ` , and ,@, external function interface, port reads and writes, call/cc, and loadable libraries -- all in a JIT compilation mode.

But I doubt that it will be ready before the release of FBSL v3.5 Final. That's a tremendous amount of work but that's what I will surely do. :)

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #788 on: September 16, 2014, 12:00:53 PM »
Hi Mike,

Good to hear ....   "bon courage"   then ...

Good you consider vectors -- my experience is that something as a 1.000.000 element list is manipulated about 20-50x slower than a vector, and luckily Scheme has (vector->list ) and (list-> vector ) to convert between the two ,
something CL does not have, but in CL one can index lists (elt list index) ... however this of course is a slow mechanism (it has to travel through the pointers anyway).  (NewLISP has (array-list ) and (array ) -- and CL (make-array  ).

the French "chez" is often used as a location definition ...

so ,   chez vous (the polite form)   at your place , or at your location          .. chez toi (the informal -- between friends etc ...)
chez nous (at our place/location).  -- chez moi /   chez Charles etc .. etc ...

So often for a restaurant , or a pub or ;...          Chez Mike , servant [ better ; on sert  -- or more sloganesque "ici" - here  ] les meilleurs vins et boissons      --- at Mike's place, serving the best wines / drinks  ...  p.e.

so probably    ..  Chez Scheme  ...    and then the little brother Chez petite Scheme -> petite Chez

Salutations, Rob
« Last Edit: September 16, 2014, 12:13:45 PM by RobbeK »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #789 on: September 17, 2014, 08:00:55 PM »
Hehehehehe, looks like it's going to be very, very speedy even if only as a toy.... ;)

.

JRS

  • Guest
Re: Lisp in Basic
« Reply #790 on: September 17, 2014, 08:06:02 PM »
Excellent Mike!

O2 is finally part of the Lisp in BASIC family.

Are you close with the SB update of SBLisp?


Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #791 on: September 17, 2014, 08:18:31 PM »
SBLisp and FBLisp are at the same stage where I left off earlier. Didn't touch any of that stuff for awhile but now that Charles has fixed his integer division (can't say it was without some gentle pressure on my behalf hehe), I can populate OxyLISP's symbol hash table correctly. That gave this toy project a boost and OxyLISP is emerging now on the scene the first one of the three. I won't be developing a DynC replica of it (got involved with a no-nonsense LISP JIT compiler instead) but I will finalize both SBLisp and FBLisp when I'm through with their nimble brother... :)

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #792 on: September 18, 2014, 07:27:47 AM »
Hi,

My initial benchmarks are showing that OxyLISP is some 100+ times faster than SBLisp or FBLisp. See it yourselves in the attached snapshot that's running a doubly recursive fibo(17) in OxyLISP vs. FBLisp. :)

Can't test it on larger numbers though because OxyLISP's garbage collection is still ailing and the bug is somewhat elusive.

[UPD] I've just seen OxyLISP doing fibo(17) in 16 milliseconds. :)

[UPD2] Here's a much more vivid example of OxyLISP's speed doing ackermann(3, 2) in 0 milliseconds vs. FBLisp's 843 milliseconds. :D

.
« Last Edit: September 18, 2014, 08:31:50 AM by Mike Lobanovsky »

Charles Pegge

  • Guest
Re: Lisp in Basic
« Reply #793 on: September 18, 2014, 08:17:46 AM »
Hi Mike,

You can use explicit garbage collection by using bstring instead of string. Bstrings are released with frees.

This may be required in subroutines where local strings are created recursively. Local strings are only released at the end of functions.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #794 on: September 18, 2014, 08:43:46 AM »
No no Charles,

OxyLISP's garbage collection relates to its stack machine' numeric "heap" where there are no strings but rather two "pages" of numeric arrays, each "page" containing one integer array, for current <datum> types, and the other, double one, for actual numeric values of the <datum>s. (terminology is Lispish)

GC here means marking the heap "locations" that have no current references in the running code <environment>s as vacant, and possibly regrouping these vacant "locations" into one large pool of free program "heap" ready for reuse. Regrouping is done from the active "page" into the passive one, whereupon the "pages" are swapped. That's why I asked you for the best method to swap array references.

The "stack" proper is also a pair of integer and double arrays that stores <datum> types and "pointers" to (actually indices of) <datum>s' types and values in the program "heap", and also "pointers" to (indices of) "heap" values that denote <datum> <environment>s (actually visibility scopes).

So, GC here is also to be understood in its Lispish sense.

O tempora, o mores! :D


(P.S. Charles, I need a command line splitter function. If you have some, please post one in my new thread on the Problems board)
« Last Edit: September 18, 2014, 09:00:37 AM by Mike Lobanovsky »