Author Topic: Lisp in Basic  (Read 208062 times)

0 Members and 2 Guests are viewing this topic.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #120 on: August 04, 2014, 08:44:11 AM »
!!! JOHN WAKE UP !!!

 :o :'( ;D

Just copy-paste this:

Code: [Select]
(define factorial (lambda (n)
(if (<= n 0)
1
(* n (factorial (- n 1)))))))

Charles Pegge

  • Guest
Re: Lisp in Basic
« Reply #121 on: August 04, 2014, 08:54:47 AM »

How would you make an average function, Mike? - taking a variable number of params.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #122 on: August 04, 2014, 08:58:33 AM »
Charles,

This is my first attempt at Lisp in maybe 30 years. Frankly, I don't know yet. :)

I need to RTFM. :)

BTW I posted a link to its manual. Have you seen it?

JRS

  • Guest
Re: Lisp in Basic
« Reply #123 on: August 04, 2014, 09:08:34 AM »
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
0](define factorial (lambda (n)
2](if (<= n 0)
3]1
3](* n (factorial (- n 1)))))))
FACTORIAL
0](factorial 8)
40320
0]

Success!

Damn, it is fast!

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #124 on: August 04, 2014, 09:13:16 AM »
My sincere congratulations again. :)

Hehe, it does floating point on much larger numbers as fast as it does integers. But of course more precise benchmarks won't do any harm.

Charles Pegge

  • Guest
Re: Lisp in Basic
« Reply #125 on: August 04, 2014, 09:14:53 AM »
Yes I saw the manuel, thanks Mike. I wish people wouldn't use PDF - it impedes lookup.

If you smoke you will burst into flames in those temperatures!


JRS

  • Guest
Re: Lisp in Basic
« Reply #126 on: August 04, 2014, 09:19:17 AM »
Quote
My sincere congratulations again.

I can't thank you enough for all the effort you put into this.

I'm happy we both got something out of this.

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #127 on: August 04, 2014, 09:27:00 AM »
Hi Mike,  ... that's a gun  :P

..  here, the French keyboard is also not complete ...   missing the "œ" as in L'œuf  (the egg) .. 

Well, I think I'll try those lisp's-in-basic ....

In NewLisp (script) things run rather fast I think  (times are in mSec's)  qzz attached.

best Rob

.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #128 on: August 04, 2014, 09:28:59 AM »
Charles,

The vocabulary seems to support map and for-each "procedures" that accept functions and lists as srguments. So I think varargs are not an issue.



John,

I'm also glad we did it. It's been our common effort; thanks a lot for your advice and assistance.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #129 on: August 04, 2014, 09:41:26 AM »
Rob,

We can't yet time SB and FBSL directly because FBSL uses an instantaneous DIM for its arrays while John has to For/Next or Splita() his memory into arrays, which takes considerable time. Thus SB is in a worse position if we compare the times to launch and run the executable. Lisp as it is doesn't offer any timing either. We have to cut into the source code and put the timing procs in its core to be able to measure the loop itself.

Regretfully there isn't anything like (do) or other iteration in this implementation. The author says there's no need for it since there are lists, lambdas, (map), and (for-each). So converting/adapting Scheme-style code to this Lisp will be sort of a nuisance. Perhaps you could do it better than anyone of us for starters.



Charles,

I could have but I am very, very careful not to sleep in my bed with a cigarette. :D

Charles Pegge

  • Guest
Re: Lisp in Basic
« Reply #130 on: August 04, 2014, 09:43:49 AM »
Mike, could you post the manual link again, please. It has got buried somewhere in the previous pages.

The Lispish way of handling 'rest' variables: All the unnamed params get swept into a list called nexts, each param is then destructively read into item whevever (next) is invoked.

And the iteration terminates when there are no further items.

(let average "( / ( + (next) item) (count) ) ")

Code: [Select]
( let average "
    ( /
      ( +
        (next)
        item
      )
      (count)
    )
")

( average 1 2 3 4 5 ) ; 3
« Last Edit: August 04, 2014, 10:03:03 AM by Charles Pegge »

JRS

  • Guest
Re: Lisp in Basic
« Reply #131 on: August 04, 2014, 09:54:21 AM »
Quote
I could have but I am very, very careful not to sleep in my bed with a cigarette.

I haven't smoked inside my house for over 20 years. This is an outside bad habit.


RobbeK

  • Guest
Re: Lisp in Basic
« Reply #132 on: August 04, 2014, 10:05:03 AM »
Looks very promising Charles,  is there a version fit for testing ??

"The author says there's no need for it since there are lists etc...  " , ah, ok .. the Scheme filosophy ,  but these are slower than iterative processing (and more memory consuming) ,   and Racket Scheme nowadays has   for   for/list   for/sum   for/product   for/vector etc .. etc ..

seems they try to tell something as ,   use (mapping, recursion etc .. ) for prototyping and translate into iteration for the final product ...   (operation on a (lisp (NewLisp and Common Lisp)) array (indexed) is also much faster than a list (which is stichted together by pointers ))

As said -- slowly imperative iterative processes become acceptable in the "newer" Lisps and I think also the vice-versa things happen. 

best Rob





Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #133 on: August 04, 2014, 10:10:14 AM »
Charles,

Here's a direct link.

And your syntax for average looks very elegant indeed. But John and I aren't yet so good at this script as to add our own primitives to it like (time) or (next) etc. The time will come eventually, as e.g. the math library is very poor etc., but not now.



John,

I'm using my balcony for this purpose. It does help cut down on tobacco, especially in winter. :)



Rob,

If these timings are really in msec, then the actual benchmark may be anywhere between 8 and 16 msec because the resolution of Windows' own system timer is 15..16 msec only and fluctuating.

Anyway, we can say anything definitively only after real benchmarking. Also, FBSL has the DynC ace up its sleeve so if I ever get interested, I might add a faster include module rewritten in JIT-compiled C.

JRS

  • Guest
Re: Lisp in Basic
« Reply #134 on: August 04, 2014, 10:18:46 AM »
Here is my task list for the SBLisp version.

  • Move Mike's fixes from his QBLisp converted SB version to my cleaned up (formating) version.
  • Add in (about) that will give credit to the author and Mike / I for the SB version and remove the text from the startup.
  • Get library (ext. modules) support working. The SDL_gfx has a precision timer function which can be used for benchmarking routines.

I would like to discuss an agreed upon syntax for the Lisp-In-BASIC versions adding library add-ons.