Oxygen Basic

Information => Open Forum => Topic started by: Aurel on July 27, 2014, 08:31:36 AM

Title: Lisp in Basic
Post by: Aurel on July 27, 2014, 08:31:36 AM
F
Title: Re: Lisp in Basic
Post by: Charles Pegge on July 27, 2014, 06:37:40 PM
projectsA/LeanLisp/Lispish

quietly incubating :)

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on July 27, 2014, 07:13:50 PM
Time to open up Oxygen's own Lisp subforum and promote RobbeK to Chief Moderator. :)
Title: Re: Lisp in Basic
Post by: Charles Pegge on July 27, 2014, 07:47:25 PM
Good!

I was going to say: there may be a problen with DEP (data execution prevention) under linux/wine. This applies to a few of the tests at the end of LispishTest2 involving o2 dynamic compiling.

Apart from those tests, this is fully interpreted code with optional tokenising of core functions, but no Data Execution.


LeanLisp is based on general LISP principles, as I understand them,  rather than any known LISP.
Title: Re: Lisp in Basic
Post by: Charles Pegge on July 27, 2014, 08:59:45 PM
Maybe start with a system like one of those pre-pc home computers. Imagine one that has LISP as the resident language instead of BASIC.

Will need some core graphics functions to supplement console i/o.
Title: Re: Lisp in Basic
Post by: RobbeK on July 28, 2014, 01:06:18 AM
Hi all,

There's a simple way to combine NewLisp and Basic (tB , GFA , FB , ....  ).
This has the advantage of using a full strength Basic and Lisp at the same time, and in this case (attached) also using Petr's excellent module (and if needed combine it with Oxygen !!!  ).
The program is just a start for something IMO interesting.  I used partly Lisp because i used 2 conditional mappings , as by the variadic nature of Lisp it has some function to test if the object is a symbol, a number , a list , a  ....   etc  , furthermore , mapping is an easy mechanism (as can be seen in the code , it will need some more code in an imperative, iterative way ...

(code is just the start of something,,   ...   )

best Rob

(source, bundle, dll in attachment)  -- use the arrow keys / Pg U/Dn for some animation
 addendum : l3D b.exe for the complete bundle (incl newlisp.dll)


.
Title: Re: Lisp in Basic
Post by: RobbeK on July 28, 2014, 02:02:57 AM
Hi John,

Nothing standard in CL  (common Lisp)  ..  infact imho everything outside the ansi standard common lisp is somewhat of a disaster.  (it already starts with the FFI  (foreign function interface)  there's ffi , cffi , uffi ....  after a while one starts collecting dependencies an nothing (if working) is compatible any more ...   (I use Japi most of the time -- but some days ago I found serious problems to combine it with OpenGL , glu(t) .. though I could set up the callback functions for keyboard, mouse, joystick , idletime etc ...   
(I think the CLisp came with Texas Instrument graphics from the mid 1980's   ::)


best Rob
Title: Re: Lisp in Basic ( 4 fun --- the truth about Lisp)
Post by: RobbeK on July 28, 2014, 03:01:14 AM
In which the truth about lisp is revealed :

Learning lisp will alter your life.

Your brain will grow bigger than you ever thought possible.

You will rewrite all of your applications in just a handful of lines

Society will shun you. You will shun society.

You will become disatisfied with everything and everyone around you.

Lisp is so simple to learn that you can learn lisp in just a few minutes. I just learnt it while I was waiting for a bus.

Lisp is so simple that you can implement it in any language in just a few pages of code. This might never happen though, because once you've learnt lisp you'd never want to write anything in any language other than lisp, so you wouldn't bother implementing lisp in any language other than lisp.

Lisp can be fully implemented in lisp in just a handful of lines. I just implemented lisp in lisp, fully, while i was hopping onto a bus and paying for my bus ticket all at the same time.

When you become a lisper, you will laugh at jokes that no one else thinks are funny. You will know things that cannot be expressed in ordinary imperative language.

You will think people are idiots when they state things like "Hi, how are you?" because a lisper simply doesn't need to use such verbose constructs. Lisp abstracts away those patterns of interaction and makes them completely irrelevant. The proper way to greet a fellow lisper is just a tiny nod of the chin, and about a tenth of a wink from your left eye, then point at your tin foil hat. They will know what you mean. if they don't know what you mean then they are not a true lisp programmer and they don't matter anyway.

Lisp was invented a long time ago, before java, before C, before fortran, before computers, before people, before the earth was built. the universe itself is a lisp program so trivial that no true lisper would even both implementing it.

Lisp is so elegant that the very fact that you know even the first thing about it will qualify you for a season as principal dancer of the royal ballet. You will go out on stage in your little tutu and just scribble a few round brackets in the air with your toe. People will gasp in wonder. Unless they don't know any lisp. If they don't know any lisp then they are idiots and they don't matter.

 8)
Title: Re: Lisp in Basic
Post by: Charles Pegge on July 28, 2014, 05:23:13 AM
Hi Rob,

The first chapter is wonderfully inspiring, but it gets much more complex, and hard to follow  in later chapters.

http://www.gigamonkeys.com/book/

Lisp lacks the constructs needed for direct OS interfacing, but I agree with you that it has great potential when anchored to Basic.


Title: Re: Lisp in Basic
Post by: RobbeK on July 28, 2014, 07:18:38 AM
Hi Charles,

@ the job, I had a book from Springer Verlag, that was (while this one is praised all over) more methodic and building things in smaller educational steps ..   afraid I lost it , but not sure (didn't use it in more than 12 yrs).

in the mean time , worked a little on previous sample

- added two mappings to center the image (lisp)
- moved the building of the matrix outside the main GL rendering  loop (it's calculated once now , and put in a GL List )     (TBGL)

it starts to look a little bit as something ...  6 iterations deep to start now --  U / D in the code stands fro up and down ...

best Rob

.
Title: Re: Lisp in Basic
Post by: RobbeK on July 28, 2014, 12:16:06 PM
Hi John,

Always (when possible) with an editor using the/a REPL  -- on top the code , lower half an interactive area to test the definitions -- it's a kind of scratch area , you can test (or prototype definitions ) before saving the source.  It's very handy ..  LispWorks CL made name and fame when it was on board NASA's Deep Space One and was remotely reprogrammed.  It was not a stunt, but a necessity because the code onboard was buggy --  it was all done with the REPL (on the homebase) ,  taking definitions apart testing and debugging and re-injecting them.
After this (all in interpreted mode) Lisp has the possibility to compile definitions piece by piece.  When the interpreter encounters interpreted and compiled code, it will execute the compiled code ---  so you can mix both interpreted and compiled code, but in a way the compiling command can be inside the interpreter source. (though it can be done on the (lower) command window too for testing).  Compiling the complete source can be done both from inside the source or from the command window.   
Making stand-alone exec.'s is another difficulty in Lisp --  it just save the complete image (with heap , stack configurations and all) into a new Lisp image with a hook to the entry function of your code.   -- often for languages as Steel Bank CL upto 40 Mb.  (CLisp only needs around 5 Mb).
What I mentioned about the disastrous situation of certain packages is not correct for commercial products like LispWorks , Franz Lisp etc...   but paying £ 3000 as a hobbyist is something too expensive for me.  (their personal versions do work , they do compile .. but do not make executables , which infact is no problem if your correspondent has same installed -- however to be fair, I don't do such things ).

One that *is* free an has it all (and more), is Racket Scheme http://racket-lang.org/  -- I should use it more (it has a number theory module onboard , complex numbers , opengl , GNU plot , lazy and strict evaluation switch , runs perfect under Linux and Windows etc ...   the language goes that far, that inside the REPL drawing just can be copied and pasted (even on documents set up on DrRacket )  ...  but with its 1000s and 1000s definitions, I'm a little afraid of it ...

best Rob

Title: Re: Lisp in Basic
Post by: JRS on July 29, 2014, 08:12:18 PM
FYI - The Script BASIC Lisp effort has been moved to the Script BASIC forum (http://www.scriptbasic.org/forum/index.php/topic,316.0.html).
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on July 30, 2014, 11:28:06 AM
Hello Rob,

Can I have your expert opinion on the functionality of Charles' implementation of Lisp as compared to tradition? (I'm leaving arbitrary precision and similar extremes out of the scope of this question)

What else does it need structurally to become fully usable/competitive?
Title: Re: Lisp in Basic
Post by: JRS on July 30, 2014, 03:25:00 PM
I would say that an interactive Lisp interpreter is must. There are a lot of Lisp interpreters and compilers out their and if one is to take competing in that realm seriously, it could be a project all on its own.

I was more interested in what it takes to convert a Quick BASIC program to Script BASIC and getting a Lisp interpreter out of the deal was icing.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on July 30, 2014, 11:50:51 PM
Actually it won't take very long if one is aware that:

1. QB45 arrays are 1-based, not 0-based.

2.
Code: [Select]
FOR x = 0 TO maxheapsize
  heaptype[x] = 0
  heaptype[x,0] = 0
  heaptype[x,1] = 0
  heapvalue[x] = 0
  heapvalue[x,0] = 0
  heapvalue[x,1] = 0
NEXT x

is not the same as

Code: [Select]
FOR mem = 0 TO MAXHEAPSIZE
HEAPtype[mem,0]=0
HEAPtype[mem,1]=0
HEAPvalue[mem,0]=0
HEAPvalue[mem,1]=0
NEXT mem

3. ERR is a QB45 system error keyword and its value is specific to QB45 rather than SB; so ON ERROR GOTO HandleInternalError and the entire HandleInternalError: have no meaning in SB.

4.
Code: [Select]
DATA{"CONS"}=1
DATA{"CAR"}=2
DATA{"CDR"}=3

and

Code: [Select]
FOR p=0 TO UBOUND(DATA) STEP 2
  i$ = DATA[p]
  primnum = DATA[p+1]

which start at index 0 are not the same as

Code: [Select]
' [0,0]/[0,1] are dummy pair
Primitives[0,0]=""
Primitives[0,1]=0
Primitives[1,0]="CONS"
Primitives[1,1]=1
Primitives[2,0]="CAR"
Primitives[2,1]=2
Primitives[3,0]="CDR"
Primitives[3,1]=3

and

Code: [Select]
FOR prm=1 TO MAXPRIM
I=Primitives[prm,0]
PRIMNUM=Primitives[prm,1]

which start at index 1.

5. QB45's variables that appear only in GoSub/Return blocks have local scope unlike those in SB, therefore the "p" variables cannot appear in different GoSub/Return blocks or they will interfere with one another.

6. QB45's

Code: [Select]
ClearStackLoop:
    IF BSD% <> 0 THEN BSD% = BSD% - 1: RETURN ClearStackLoop
    GOTO LispReadEvalPrintLoop

does not mean

Code: [Select]
ClearStackLoop:
IF bsd<>0 THEN
   bsd=bsd-1
   REM RETURN ClearStackLoop
   RETURN
END IF
GOTO LispReadEvalPrintLoop

but rather

Code: [Select]
ClearStackLoop:
IF BSD<>0 THEN
BSD=BSD-1
GOTO ClearStackLoop
END IF
GOTO LispReadEvalPrintLoop

7.
Code: [Select]
  IF pvalue=38 THEN GOTO DoCos
  IF pvalue=38 THEN GOTO DoAtan
  IF pvalue=39 THEN GOTO DoGC
  IF pvalue=40 THEN GOTO DoEvl

will never allow one to do atan, or garbage collect, or evaluate anything, etc.



I don't promise all those evident fixups will reanimate SB Lisp at once and in full but they will surely allow one to at least enter, garbage collect, and exit gracefully. Yet I don't fully see how SB may benefit from such medieval sources.
Title: Re: Lisp in Basic
Post by: RobbeK on July 31, 2014, 01:26:08 AM
Hi all,

I'm afraid my knowledge about the deeper architecture of Basic, C , etc .. is rather poor. 
But in Lisp uses the pointer as building block ( just something known "As Any Pointer" , no "pitch" etc.. declared -- it is hidden anyway and completely controled by the system).
This makes that if you say    a=b   ( a := b ;  not a==b ) then it just means a and b share the same pointer whatever the object it points to may be.  This already needs some care (when dynamical scoping is used) and the reason you need several mechanism (as an example) to test equality --  do they point at a same object , or is if not is the outcome of the function they point to the same ..    (eql a b) versus (= a b)  ..  (NewLisp uses lexical scoping and here in both cases "=" can be used ).
Working with ponters make it easy to nest objects of any type, size, depth and manipulate them .. the objects do not move in memory, just the pointers are manipulated - it consequently needs frequent and intensive garbage collection (once again NewLisp uses ORO memory management    .............     http://www.newlisp.org/MemoryManagement.html

other tech. info   (web quotes ) :

"In Lisp, functions are first class objects-- they're a data type just like integers, strings, etc, and have a literal representation, can be stored in variables, can be passed as arguments, and so on."

" In Lisp, all variables are effectively pointers. Values are what have types, not variables, and assigning or binding variables means copying pointers, not what they point to."

" Lisp programs are trees of expressions, each of which returns a value. (In some Lisps expressions can return multiple values.) This is in contrast to Fortran and most succeeding languages, which distinguish between expressions and statements.

It was natural to have this distinction in Fortran because (not surprisingly in a language where the input format was punched cards) the language was line-oriented. You could not nest statements. And so while you needed expressions for math to work, there was no point in making anything else return a value, because there could not be anything waiting for it.

This limitation went away with the arrival of block-structured languages, but by then it was too late. The distinction between expressions and statements was entrenched. It spread from Fortran into Algol and thence to both their descendants.

When a language is made entirely of expressions, you can compose expressions however you want."

"There is no real distinction between read-time, compile-time, and runtime. You can compile or run code while reading, read or run code while compiling, and read or compile code at runtime.

Running code at read-time lets users reprogram Lisp's syntax; running code at compile-time is the basis of macros; compiling at runtime is the basis of Lisp's use as an extension language in programs like Emacs; and reading at runtime enables programs to communicate using s-expressions, an idea recently reinvented as XML. "

Basic and Lisp -- The Two Kings' Children ??  -- the water between them may be very deep  ?

from the link John gave :  http://www.paulgraham.com/rootsoflisp.html

I think I prefer a full strength Basic and a full strength Lisp working together over one of these simulating the other ...

4 fun (from the people of Viaweb)
"During the years we worked on Viaweb I read a lot of job descriptions. A new competitor seemed to emerge out of the woodwork every month or so. The first thing I would do, after checking to see if they had a live online demo, was look at their job listings. After a couple years of this I could tell which companies to worry about and which not to. The more of an IT flavor the job descriptions had, the less dangerous the company was. The safest kind were the ones that wanted Oracle experience. You never had to worry about those. You were also safe if they said they wanted C++ or Java developers. If they wanted Perl or Python programmers, that would be a bit frightening-- that's starting to sound like a company where the technical side, at least, is run by real hackers. If I had ever seen a job posting looking for Lisp hackers, I would have been really worried."   8)

best Rob -- as said, my knowledge about the lower architecture of imperative languages is probably too low to make a fair compare .... 
Title: Re: Lisp in Basic
Post by: Charles Pegge on July 31, 2014, 03:49:30 AM
My LispishUtil requires about 32 core function to operate as an interpreted language. Throw in some string, maths, console and GUI, with the underlying support of static Basic, and we have a new light and fluffy :) layer for highly flexible programming.

(http://www.bbcgoodfood.com/sites/bbcgoodfood.com/files/recipe_images/recipe-image-legacy-id--745461_11.jpg)

This particular implementation, unlike classical Lisp, does not use chains of pointers, but instead uses a single elastic buffer for all records. This makes scoping and  garbage collection very simple. All values are returned in strings.

In this bare-bones system, there are no macros, and no distinction between defining a variable and defining a function.

(http://notlots.com/comics/2011-11-27Bare%20Bones.png)


It also has a few functional-programming constraints:

A user-defined function can only return 1 thing (which can be be a list or another function). It will not alter the values of any variable passed (unlike C pointered, or BASIC byref params)

There are no static variables, so a function cannot retain state between calls - all the variables are dis-allocated when the function returns.



 
Title: Re: Lisp in Basic
Post by: JRS on July 31, 2014, 07:57:00 AM
Thanks Mike !!!

Last night I discovered that the symbols$[] array isn't being populated. (only a couple symbols were present) That seems to be the major issue. I was using a base 0 for arrays so that may be another issue I didn't realize.

After fixing the symbols$[] array I will go down your list.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on July 31, 2014, 09:26:55 AM
No problem John,

Here's the SB Lisp listing with these bugs fixed and array population corrected. However, it must still be having a few bugs dormant as it fails to do eval correctly (numbers still aren't recognized as type NUMBER/3 but rather type SYMBOL/4 somehow). Nonetheless it's way ahead of your original submission.

P.S. print statements that appear in lower case immediately on the left of the listing are my debugging aids and may be safely deleted.

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on July 31, 2014, 09:41:14 AM
Charles, Rob,

Thanks a lot for your input. It seems like Lisp has been almost as popular for indie development as BASIC.

And Charles is looking so happy with this mouth-watering summertime cake. I guess he's a little tired of BASIC and needs some other tchotchke to play with for a change. :)

Isn't it cool to see another language built on top of what one already has done with one's own hands? 8)
Title: Re: Lisp in Basic
Post by: JRS on July 31, 2014, 09:54:58 AM
Quote
Here's the SB Lisp listing with these bugs fixed and array population corrected. However, it must still be having a few bugs dormant as it fails to do eval correctly (numbers still aren't recognized as type NUMBER/3 but rather type SYMBOL/4 somehow). Nonetheless it's way ahead of your original submission.

P.S. print statements that appear in low case immediately on the left of the listing are my debugging aids and may be safely deleted.

That is so cool that you would help the SB project out and resolve these QB to SB issues. You are a true friend!

Quote
Isn't it cool to see another language built on top of what one already has done with one's own hands?

It just validates that BASIC is the foundation of all languages going forward.

Quote
If I had ever seen a job posting looking for Lisp hackers, I would have been really worried.

Life is more interesting under the covers.
Title: Re: Lisp in Basic
Post by: JRS on July 31, 2014, 01:32:50 PM
(quit)  works!

That wasn't happening before. I think you are close. It seems you used my first post on the O2 forum rather than the current one I had on the SB forum. I did some cleanup on that version.

1. All variables to lower case.
2. Labels (functions ?) mixed case
3. KEYWORDS capitalized.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on July 31, 2014, 01:46:27 PM
Yes, (quit) and (gc) do work. The parser seems to work OK. I think the other keywords and primitives should work as well, but evaluation is still failing somewhere. That's where I left off.

Of course I had a look at your sources. I downloaded them from the SB site. But since those weren't working and were showing arguable approaches, I copied the original right off the Lisp in Basic site and reformatted it staying as close to the original as SB would only permit. Then I fixed up the array population problem and checked the parser for general operability.

There may still be some hidden visibility scope problem that spoils data type evaluation. The lack of DoLss (the < function) is probably due to the author's carelessness when copying the source to the site. This function might well be the last one in the listing.
Title: Re: Lisp in Basic
Post by: JRS on July 31, 2014, 02:12:47 PM
The DoLss routine missing also made the QB program error. I just added a stub to deal with it. I should e-mail to author and ask about it.

You seem very close and if you have time to take it home, that would be outstanding. I'll wait to do my format cleanup on your version when it looks like it's working.

What are your thoughts about allow extension module access from SBLisp? I have seen a few different approaches to this.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on July 31, 2014, 02:42:24 PM
I don't think a letter is really necessary. DoLss should be an exact replica of DoGtr (whatever) barring the sign of comparison. I think it can be reconstructed from the existing code.

I left all the former uppercase intact to distinguish it from my deliberate lowercase that I'm adding at debug time. Probably it should stay that way till it starts to function in full.

I'll come back to this code this weekend. It's absolutely terribly, oppressively hot in my whereabouts these days so I'm getting my naps more often than usual. They help me to live on. Will you do me a favor and have a look at your Alaska backyard? You probably forgot to switch off that bloody HAARP oven thing again. :)
Title: Re: Lisp in Basic
Post by: JRS on July 31, 2014, 02:54:56 PM
I don't think a letter is really necessary. DoLss should be an exact replica of DoGtr (whatever) barring the sign of comparison. I think it can be reconstructed from the existing code.

Timing was perfect. I was just ready to press send.

Quote
I left all the former uppercase intact to distinguish it from my deliberate lowercase that I'm adding at debug time. Probably it should stay that way till it starts to function in full.

Okay, I'll follow your lead.

Quote
I'll come back to this code this weekend. It's absolutely terribly, oppressively hot in my whereabouts these days so I'm getting my naps more often than usual. They help me to live on. Will you do me a favor and have a look at your Alaska backyard? You probably forgot to switch off that bloody HAARP oven thing again. :)

I'm really looking forward to seeing this work. I have all kinds of ideas (like Charles) how Lisp and BASIC can complement each other.

Everything seems pleasant HERE (https://weather.yahoo.com/united-states/Washington/Anacortes-2354430/).
 
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on July 31, 2014, 03:09:08 PM
Everything seems pleasant HERE (https://weather.yahoo.com/united-states/Washington/Anacortes-2354430/).

D'oh, but that's only 26 Centigrade! We're having 36 Centigrade in the shade here and 26 has been and still is our usual nightly reading for over a week.
Title: Re: Lisp in Basic
Post by: JRS on July 31, 2014, 03:32:04 PM
THIS (http://rigaux.org/language-study/syntax-across-languages-per-language/CommonLisp.html) might be of interest to Lisp users/developers.

Lisp Intro (http://www.math-cs.gordon.edu/courses/cs323/LISP/lisp.html)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on July 31, 2014, 08:31:34 PM
That's what everyone wanted to know but was too shy to ask... :D
Title: Re: Lisp in Basic
Post by: JRS on July 31, 2014, 08:42:38 PM
Once this is working, what do you think about eliminating the stack limit check? SB will dynamically allocate the stack. UNDEF will delete it.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on July 31, 2014, 08:56:19 PM
IMO stack, data and "code" storage should always be dynamic. Fixed-length arrays are acceptable in toy interpreters only.
Title: Re: Lisp in Basic
Post by: JRS on July 31, 2014, 08:58:16 PM
You're right. Hope others get the message.  :D

BTW I figure by the time you solve the SBLisp issues, SB will have spoiled you and you will be hooked. Not having to declare anything is addicting.

Call it gut but I'm sensing REF (http://www.scriptbasic.org/docs/ug/ug_25.142.html) might come into play with SBLisp.
Title: Re: Lisp in Basic
Post by: JRS on July 31, 2014, 10:33:04 PM
FYI If you get tired of scriba lisp.sb myscript.lisp you can create a standalone SbList.exe with the following.

scriba -Eo SBlisp.exe lisp.sb

Then all you have to type is sblisp myscript.lisp.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on July 31, 2014, 11:35:17 PM
Thanks for the tip.

Just FYI,

1. FBSL allows for three levels of user stupidity:

- #Option Implicit:
--- don't declare simple variables but declare arrays and UDT's (for WinAPI compatibility), and classes;
--- don't report missing declarations and related compile-time warnings but break on compile- and run-time errors;
- #Option Explicit (default):
--- declare everything;
--- report missing declarations and related compile-time warnings and break on compile- and run-time errors; and
- #Option Strict:
--- declare everything;
--- report all warnings and break on all errors.

The display of warnings is controllable throughout the script with a #Warnings On | Off directive. All errors can be trapped and handled with an On Error ... directive and associated functions.

2. Apart from direct access to memory pointers, FBSL has three options to dereference an FBSL object:

- ReferenceOf foo = bar - dereference any object as a whole and point it to any other object by name;
- PointerOf foo = PointerOf bar - point any non-executable entity to any other non-executable entity; and
- AddressOf foo = AddressOf bar - point the entry point of any standalone procedure or object method to the entry point of any other executable entity.

@ is a shorthand for the PointerOf operator. Both PointerOf and AddressOf accept also a numeric variable or literal as the right-hand side of the assignment.
Title: Re: Lisp in Basic
Post by: JRS on August 01, 2014, 12:04:05 AM
In SB you can turn AUTOVARS on/off anywhere in script making assignment before use required. You can set the option to make compares case insensitive. You can make all variables in a FUNCTION/SUB local by default. There are a few other SB options but these are the ones I use normally.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 01, 2014, 12:28:22 AM
Peter Verhas did a very clever job with his choices for the SB vocabulary. I guess he was fond of coding SB programs as much as SB itself.

FBSL's #Option choices reflect its becoming more mature as more and more complicated projects were evolving with time. It's impossible to maintain a multifile #Option Implicit project efficiently. You can already see it even in SB Lisp.

The lack of possibility to declare an SB array without assignment is a drawback. "Initialization" of a large (say, 32MB) array in a client-side For/Next loop is extremely time-consuming as compared to Dim a[33554432] which is done on the server side by malloc() or calloc() instantly and without memory fragmentation.
Title: Re: Lisp in Basic
Post by: JRS on August 01, 2014, 01:14:03 AM
Quote
The lack of possibility to declare an SB array without assignment is a drawback. "Initialization" of a large (say, 32MB) array in a client-side For/Next loop is extremely time-consuming as compared to Dim a[33554432] which is done on the server side by malloc() or calloc() instantly and without memory fragmentation.

If the Array you wish to DIM is a single dimension, then this is an equivalent.

SPLITA STRING(1000001,"0") BY "" TO a

This is the same a DIM a(1000000) with a base of zero.

My plan is to extend the Tools extension module to DIM array structures at the C level.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 01, 2014, 01:40:10 AM
SPLITA STRING(1000001,"0") BY "" TO a
This may be a good palliation in some special cases.

Quote
My plan is to extend the Tools extension module to DIM array structures at the C level.
This looks like the most reasonable direction to go provided C-compatible array and structure declarations go into the extension together. Think of an array of UDT's with arbitrary member alignment requirements - common practice in C but totally impossible in SB so far.
Title: Re: Lisp in Basic
Post by: JRS on August 01, 2014, 01:45:21 AM
Here is how to DIM a two dimensional array.

Code: [Select]
SPLITA STRING(1000001,"0") BY "" TO a
SPLITA STRING(500001,"0") BY "" TO b

a[0] = b

PRINT UBOUND(a),"\n"
PRINT UBOUND(a[0]),"\n"

PRINT a[0,500000],"\n"

jrs@laptop:~/sb/sb22/sblisp$ time scriba dim.sb
1000000
500000
0

real   0m0.561s
user   0m0.392s
sys   0m0.164s
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: JRS on August 01, 2014, 02:35:38 AM
Actually it can get a little more interesting. In this example the first dimension is initialized to 1000000 zeros (long) and the second dimension is dimensioned to 500000 zstr's. That could be further expaneded out with assiciative arrays as well. There is no practical dimension limitation with structure, size or type.

Code: [Select]
SPLITA STRING(1000001,"0") BY "" TO a
SPLITA STRING(500001,0x0) BY "" TO b

a[0] = b

PRINT UBOUND(a),"\n"
PRINT UBOUND(a[0]),"\n"

PRINT ASC(a[0,500000]),"\n"
PRINT LEN(a[0,500000]),"\n"

jrs@laptop:~/sb/sb22/sblisp$ time scriba dim.sb
1000000
500000
0
1

real   0m0.549s
user   0m0.360s
sys   0m0.184s
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 01, 2014, 03:17:13 AM
Hmmm,

It doesn't look like a two-dimensional array to me, John. It looks more like a one-dimensional (byte ?) array a[1000000] with another one-dimensional (byte ?) array b[500000] assigned to the 1st element of array a[].

Otherwise I don't think you'll be able to create an almost 466GB byte array even under 64-bit SB. :)

I think a reasonably large and genuinely two-dimensional 1.86GB array (a.k.a. matrix)

Dim a[0 To 1000000, 0 To 2000] As Byte

would take FBSL only a couple microseconds to allocate and fill with zeros, which would be impossible to measure against a few calls to (relatively) turtle-slow C-based Print.
Title: Re: Lisp in Basic
Post by: JRS on August 01, 2014, 03:18:47 AM
This is the best I can do and still show flexibility.

Code: [Select]
SPLITA STRING(1001,"0") BY "" TO a

b[0] = 0
b[1] = 1.23
b[2] = "ABC"

FOR x = 0 to 1000
  a[x] = b
NEXT

PRINT UBOUND(a),"\n"
PRINT UBOUND(a[500]),"\n"

PRINT a[10,0],"\n"
PRINT FORMAT("%g",a[100,1]),"\n"
PRINT a[1000,2],"\n"

jrs@laptop:~/sb/sb22/sblisp$ time scriba dim.sb
1000
2
0
1.23
ABC

real   0m0.006s
user   0m0.000s
sys   0m0.004s
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 01, 2014, 03:35:23 AM
John,

Please take a little nap while I'm drawing a picture of what you do with your two arrays and how a two-dimensional array looks in reality.

You can't  create an empty two-dimensional array in SB in any way other than "initialize" its elements in a For/Next (or any other suitable) loop by assignment similar to the first lines in the SB Lisp source code.
Title: Re: Lisp in Basic
Post by: JRS on August 01, 2014, 03:45:46 AM
It will sink in once you try it yourself.

Good night/morning.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 01, 2014, 06:30:17 AM
Apart from all sorts of fully C-compliant static arrays for simple and arbitrarily aligned compound data types, FBSL provides an exhaustive range of non-compliant dynamically resizable "arrays" for all of the entities that it supports including ranges, collections, dictionaries, and object instances.

These dynamic "arrays" are implemented internally as doubly linked lists, i.e. quite like the "arrays" as they are known in SB. Their elements respawn to existence only when they are referenced in the code for the first time through any sort of polling or assignment, very similar to what you're showing by your latest test. Non-referenced elements remain unallocated.

Anyway here goes the diagram; it may come in handy as a reminder on your first steps with your projected SB extension module.

Have a good night's sleep, John.

P.S. BTW what will be the timing to split a string of 1Mln+1 bytes? This last benchmark doesn't correlate well with the preceding ones.

.
Title: Re: Lisp in Basic
Post by: JRS on August 01, 2014, 12:41:20 PM
Hi Mike,

The point I was trying to make was we don't have to use a FOR/NEXT to initialize all dimensions of an array and that array structures are dynamic and free form and hold any type of data or a reference to another array. You are absolutely correct that SB arrays are NOT C standard arrays and can't be accessed in the traditional way. What we have as a helper is the SPLITA/SPLITAQ functions as a C way of initializing arrays structures quickly.

You will see that SB takes the side of ease of use and interpreter intelligence over optimal performance. 10 years ago when we were running on single cores and sub ghz speeds, the difference may have been detectable.

OT - I just looked at Rene's GUI under Win8 and it looks like Microsoft is going back to its Win2K roots. :-(
Title: Re: Lisp in Basic
Post by: JRS on August 01, 2014, 03:56:18 PM
Quote from: Mike
BTW what will be the timing to split a string of 1Mln+1 bytes? This last benchmark doesn't correlate well with the preceding ones.

In the last example, the primary dimension is only 1001 elements and was pre-built unsing SPLITA. This was unneeded as the FOR/NEXT could build the index on the fly and add the b mixed array once the element was created to proved the second dimension.

Code: [Select]
b[0] = 0
b[1] = 1.23
b[2] = "ABC"

FOR x = 0 to 1000
  a[x] = b
NEXT

PRINT UBOUND(a),"\n"
PRINT UBOUND(a[500]),"\n"

PRINT a[10,0],"\n"
PRINT FORMAT("%g",a[100,1]),"\n"
PRINT a[1000,2],"\n"

jrs@laptop:~/sb/sb22/sblisp$ time scriba dim.sb
1000
2
0
1.23
ABC

real   0m0.011s
user   0m0.008s
sys   0m0.004s
jrs@laptop:~/sb/sb22/sblisp$

Here is the same code with the SPLITA used to per-inialize the a array.

jrs@laptop:~/sb/sb22/sblisp$ time scriba dim.sb
1000
2
0
1.23
ABC

real   0m0.007s
user   0m0.000s
sys   0m0.004s
jrs@laptop:~/sb/sb22/sblisp$
 
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 01, 2014, 07:55:50 PM
[OT]

Why, it's a rather nice attempt to create a functional GUI set in an OpenGL environment. Windows (and Linux, for that matter) forms and common controls are non-existent within the OGL canvas. Each interactive OGL application has to create its own HUD's (Head-Up Displays) to compensate for that missing functionality.

It's pretty much the same as what Charles is doing in his O2 Controls and Control Panels effort. And Rene's ideas of consistency with the Windows environment he's working in are not bad at all. It's another question if Windows 8(.1) GUI is suitable for a desktop PC at all tho.

[/OT]
Title: Re: Lisp in Basic
Post by: JRS on August 01, 2014, 08:10:28 PM
OT

I missed that Rene's UI was OpenGL (TBGL) and was detracted by how ugly the Windows 8.x UI looks. I'm in no hurry to go there. Who knows were PC's will end up in the food chain. Personally most of my development efforts are in business web applications. The cloud providers like Amazon are proving the server room hardware so trying to make a buck these days as a VAR is challenging.



 
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 01, 2014, 08:44:01 PM
[OT CTD.]

I'm pretty sure desktops are going to hold on for quite some time. IMO it's more a question of how much more of their most common human tasks all these newer and simpler handheld gadgets and gimmiks are going to be able to mimic. It's going to be sorta eternal, like television vs. computer.

Sure if there were any choice, Win 8's Metro theme would be the last one on my mind to select for my everyday use. It looks like one more of those enhanced contrast options for handicapped users to me. Or else signifies serious handicaps in the minds of MS design department staff.

[/OT]
Title: Re: Lisp in Basic
Post by: JRS on August 01, 2014, 11:10:56 PM
Mike,

Any progress to report with SBLisp?

Is there anything I can do to help?

I created a Bitbucket repository (https://bitbucket.org/ScriptBasic/sblisp) for the SBLisp project and added you as a contributor and gave you write privileges.

John

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 02, 2014, 11:16:56 AM
Thanks John.

I've fixed one more problem in Lisp print (QB45's Str$() has weird formatting for non-negative numbers), and I've also added DoLss (it was indeed a matter of changing > to <). I haven't found anything else of interest yet. But I think I've seen a recursive GoSub somewhere and I think this may cause all sorts of headaches for SB. I lost the exact spot however and can't find it again easily 'cause of all this medieval bloat in the original code.

P.S. 10:00 a.m.; Sat Aug 2, 2014; Minsk

.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 02, 2014, 11:45:12 AM
Refuge

(http://domaingang.com/wp-content/uploads/2014/01/igloo-snow.jpg)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 02, 2014, 12:06:19 PM
!!! Shelter !!!

Seems like we're changing from Potato Land into Banana Land. And yes, our skins and hair are getting darker too.

:D :D :D
Title: Re: Lisp in Basic
Post by: JRS on August 02, 2014, 12:11:46 PM
Quote from: Mike
I've fixed one more problem in Lisp print (QB45's Str$() has weird formatting for non-negative numbers), and I've also added DoLss (it was indeed a matter of changing > to <). I haven't found anything else of interest yet. But I think I've seen a recursive GoSub somewhere and I think this may cause all sorts of headaches for SB. I lost the exact spot however and can't find it again easily 'cause of all this medieval bloat in the original code.

Thanks for the update Mike!

Is SBLisp able to evaluate an expression yet?

The level of recursion in SB can be 0 = (until you run out of memory) or you can set a max so you don't seg. fault / exception err) and this is part of the SB basic.conf settings. A scriba -D will display to the terminal your current SB compiled configuration settings.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 02, 2014, 12:17:09 PM
No, not yet. It still doesn't recognise numbers correctly and mistakes them for primitives. I'm also seeing that some (but not all) hash codes in the SB table differ from their equivalents in QB45.

We're not dealing with true SB recursion here as these are not true functions. These are just recursive pieces of QB45 code which have their own scope (remember the "p" bug?). I strongly doubt Peter would go that far in his implementation of this ancient BASIC functionality. I certainly didn't. Neither did Charles, to the best of my knowledge. thinBasic doesn't have all this GoTo/GoSub mess at all.
Title: Re: Lisp in Basic
Post by: JRS on August 02, 2014, 12:19:54 PM
That HASH routine seemed suspicious to me.

Have you tried Dave's debugger with SPLisp?

Title: Re: Lisp in Basic
Post by: Charles Pegge on August 02, 2014, 12:23:33 PM

Effective Water cooling: :)

(http://thebodyshop-uk-blog.azurewebsites.net/wp-content/uploads/2-Soak-the-Feet-Reduced-298x300.jpg)
Title: Re: Lisp in Basic
Post by: JRS on August 02, 2014, 12:34:57 PM
I have one of those but powered to circulate the water and rotating disks to smooth your feet. A requirement for under the desk. (wishing it were Milla)  ;D
Title: Re: Lisp in Basic
Post by: JRS on August 02, 2014, 12:44:00 PM
In SB FALSE=0 and TRUE=-1. In QBLisp TRUE=NOT(FALSE).

Might be an issue.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 02, 2014, 12:54:41 PM
1. Milla unda teh desk rulez!

2. I need that bowl straight on my head, not for my feet.

3. QB45's NOT FALSE evaluates to -1. You can check it with PRINT. QB45 doesn't define the FALSE and TRUE constants internally.

4. I'm doing a quick port to FBSL now to see if it would work there.
Title: Re: Lisp in Basic
Post by: JRS on August 02, 2014, 01:04:41 PM
Quote
4. I'm doing a quick port to FBSL now to see if it would work there.

Since we are telling secretes, I'm working on modernizing the code a bit with CaSe and +=, -=, .... I will send it to you for review and see if you want to use it for the gold run. For me. it just makes it easier to see things as SB is typeless with no $ suffix.  (optional)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 02, 2014, 01:20:50 PM
Doesn't really matter for me right now but prettifying the final code is a good idea.

I think once it runs as expected, functionalizing it altogether might add a lot to its readability and maintainability.
Title: Re: Lisp in Basic
Post by: JRS on August 02, 2014, 01:22:55 PM
I'm already thinking about how we add in SDL_gfx, SQLite3, ...

Title: Re: Lisp in Basic
Post by: JRS on August 02, 2014, 01:44:54 PM
Quote
We're not dealing with true SB recursion here as these are not true functions. These are just recursive pieces of QB45 code which have their own scope (remember the "p" bug?). I strongly doubt Peter would go that far in his implementation of this ancient BASIC functionality. I certainly didn't. Neither did Charles, to the best of my knowledge. thinBasic doesn't have all this GoTo/GoSub mess at all.

SB is pretty smart with its stack management allowing to jump out of a FOR/NEXT, GOSUB, ... with a GOTO and SB takes care of popping the stack.

You may want to look at the MakeNumber routine. I think SB has a POW function and I'm not sure if the ^ QB syntax is working correctly. (my guess)

Quote
. QB45's NOT FALSE evaluates to -1. You can check it with PRINT. QB45 doesn't define the FALSE and TRUE constants internally.

Since SB's TRUE/FALSE are built in constants (F=0 T=-1) and the QBLisp program is using variables, I think the NOT(FALSE) means (F=0 T=anything not zero)

Also be aware that SB has INT and FIX which are similar but handles rounding differently. (up/dn)

Does SB compares need to be case insensitive? (INSTR,  IF a$ = b$ THEN , ...) If YES we need to enable that SB option in SBlisp.


Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 02, 2014, 04:36:16 PM
Thanks for the tips, John.

1. If FALSE is defined as 0, then NOT FALSE evaluates arithmetically to (short int)-1 in QB and VB. SB and O2 will generate (long)-1. FBSL will generate (unsigned int)1.

For Boolean logic, there's no difference what the arithmetic value of TRUE is. The logic defines FALSE=0 only and everything else is TRUE on default. It's just a matter of BASIC's (artificial) tradition to define its TRUE as -1.

The code doesn't check any entity for arithmetic equality with TRUE. It only uses NOT FALSE in IF conditionals where any non-zero value will do.

2. INT() isn't needed in the hash code at all. SB and FBSL (and QB45 BTW) support integer division \ which eliminates the need for all this trickery. Let's leave it at the author's discretion.

3. The only other place where INT() is used is not correct either. Lisp requires explicit Floor() in its DoFloor portion which is not the same as BASIC's INT(). It should round its positive argument down to the closest lower integer but it should round its negative argument to the closest upper integer. QB45's INT() works like a Round() function which rounds its argument arithmetically to the nearest absolute integer with a corresponding sign. This isn't correct for a Floor() call.

IIRC FIX() is simple truncation. Please correct me if I'm mistaken.

FBSL has a % cast for truncation and also built-in Round(), Floor() and Ceil() functions.

4. FBSL Lisp seems to be working OOTB even with #Option Implicit on (i.e. no declarations at all except for the six arrays used in the code). There's some minor problem with its printing a little garbage at its prompt but I'll fix it after a short lunchbreak.

This is good news which means SB should also work sooner or later as there are no more latent bottlenecks in the code. Perhaps I simply dreamed up that "recursive GoSub" nightmare in my hot and sweaty drowsiness.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 02, 2014, 05:28:25 PM
Hello John,

Here comes FBSL Lisp.

.
Title: Re: Lisp in Basic
Post by: JRS on August 02, 2014, 05:29:24 PM
Quote
3. The only other place where INT() is used is not correct either. Lisp requires explicit Floor() in its DoFloor portion which is not the same as BASIC's INT(). It should round its positive argument down to the closest lower integer but it should round its negative argument to the closest upper integer. QB45's INT() works like a Round() function which rounds its argument arithmetically to the nearest absolute value with a corresponding sign. This isn't correct for a Floor() call.

IIRC FIX() is simple truncation. Please correct me if I'm mistaken.

SB INT (http://www.scriptbasic.org/docs/ug/ug_25.88.html)

SB FIX (http://www.scriptbasic.org/docs/ug/ug_25.60.html)

FYI - Reason for the O2 forum being down was due to a couple MySQL threads being corrupted. Seemed to only effect the O2 forum. Strange!
Title: Re: Lisp in Basic
Post by: JRS on August 02, 2014, 05:31:51 PM
Quote
Here comes FBSL Lisp.

How do you spell happy again?  ;D

I think we are close with SB. Then I can be as happy as you are right now.



Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 02, 2014, 05:36:01 PM
John,

In fact, if I'm looking happy here then it's you I'm being happy for. Frankly I, for one, didn't have the slightest shade of doubt it will work almost instantaneously. I still remember I was first modeling FBSL after MS BASIC. :)

If anyone wants the FBSL script, just let me know.

(Edited to correct faulty English)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 02, 2014, 05:39:36 PM
Oh,

That means SB FIX() works like true Floor() - so we'll be using it in DoFloor instead of INT().
Title: Re: Lisp in Basic
Post by: JRS on August 02, 2014, 05:51:34 PM
Quote
That means SB FIX() works like true Floor() - so we'll be using it in DoFloor instead of INT().

Great!

Thanks for all the effort you're putting into this. Much appreciated!

FBSL Lisp Works on Wine too.


.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 03, 2014, 02:42:00 AM
Now, what are we going to do with all this LISP? :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 03, 2014, 07:26:03 AM
Let's ask Aurel - it's his thread, after all. :)
Title: Re: Lisp in Basic
Post by: JRS on August 03, 2014, 07:55:04 AM
Quote from: Charles
Now, what are we going to do with all this LISP?

Looks like Rob has a few more options than when this thread began.  8)
Title: Re: Lisp in Basic
Post by: Aurel on August 03, 2014, 08:37:04 AM
Quote
Let's ask Aurel - it's his thread, after all

well yes i started this thread ..i don't know why  ::)

I don't like LISP ..scheme ..etc  but is ok ..
I wish that i know how to create something o2 & REXX....
Title: Re: Lisp in Basic
Post by: JRS on August 03, 2014, 09:07:08 AM
Quote from: Aurel
well yes i started this thread ..i don't know why

It's the troll in you that makes you start these threads. Showing distaste for things you haven't tried is not the best way to learn and make friends. IMHO

Title: Re: Lisp in Basic
Post by: Aurel on August 03, 2014, 09:21:23 AM
troll ..troll ...ha ...ha ...ha ....
who can be bigger troll than you   ::)
learn..what ?
friends....virtual....make.....what ?
 ;D
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 03, 2014, 10:11:31 AM
.....what ?

Hahahaha, actually your spelling of this meme (http://knowyourmeme.com/memes/wat) isn't correct:
(http://www.xdtalk.com/forums/attachments/xdtalk-chatter-box/27749d1399960047-apple-helping-hide-police-wrong-doings-wat.png)




;D ;D ;D
Title: Re: Lisp in Basic
Post by: Aurel on August 03, 2014, 11:46:30 AM
....and what?  ;D
Title: Re: Lisp in Basic
Post by: Peter on August 03, 2014, 11:59:40 AM
WAT is correct, is Berliner and Westfälischer dialect.  ;D
Title: Re: Lisp in Basic
Post by: Aurel on August 03, 2014, 12:19:29 PM
naturlich und selbstverschtendlich     ;D
Title: Re: Lisp in Basic
Post by: JRS on August 03, 2014, 01:03:49 PM
Well there you have it. Another school yard brawl and Aurel having to go home and explain to mom why he got his clothes dirty.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 03, 2014, 01:39:07 PM
@Peter:

"Wat" means "was" (germ.) in the Berliner and Westfälischer dialects?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 03, 2014, 01:49:46 PM
selbstverschtendlich

Aurel,

They say Donaudampfschifffahrtselektrizitätenhauptbetriebswerkbauunterbeamtengesellschaft is the longest actually usable German word. It means The Association of Subordinate Officials of the Head Office Management of the Danube Steamboat Electrical Services. :D



Peter,

Can you spell it correctly by ear? :)
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 03, 2014, 02:20:09 PM
Longest Welsh word and contender for the World's longest domain name: :)

http://llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch.info/scripts/sound.php

Temperature there:

http://llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch.info/scripts/weather.php
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 03, 2014, 03:18:30 PM
ll-gogery-ll-ogogogosh would sound extremely poetic and cadential to my ear. :) Not sure about the rest of it though ... ("...rpwllgw..."  :o )

Oh-goh-goh! is a Russian exclamation when one sees something really mighty in size (quite suitable in this very case, I'd say :) ).

Обороноспособность (defence capability) is the only Russian word that's spelled with seven vowels "o" and none other.

The only Russian words that would feature three similar letters in a row are the derivatives of the adjective ...шеее like in длинношеее, короткошеее, кривошеее etc. which are the Russian neutral gender for long-necked, short-necked, bent-necked, etc. :)
Title: Re: Lisp in Basic
Post by: Peter on August 03, 2014, 03:30:55 PM
Hi Mike,

Quote
"Wat" means "was" (germ.) in the Berliner and Westfälischer dialects?

It means "was" : english what.

Donaudampfschifffahrtselektrizitätenhauptbetriebswerkbauunterbeamtengesellschaft
is a complexly word for dummies. Sense of this 'word' is, speak it as fast as you can.   

Donaudampfschifffahrt = Donaudampfschifffahrtsgesellschaft, this is correct. 
elektrizität_hauptbetriebswerk, are two words
bau_unter_beamten_gesellschaft, is no word.

Bauunternehmer    : Male
Bauunternehmerin  : Female
Beamte or Beamtin : Male/Female
Gesellschaft      : company

of course, I can speak this long word very fast and I can sing it.

Aurel,
naturlich und selbstverschtendlich = wrong
Natürlich und Selbstverständlich   = correct
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 03, 2014, 03:40:48 PM
Thanks, Peter! :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 03, 2014, 03:41:33 PM
And the weirdest alien name I am able to write by heart for nearly 40 years already is Mobutu Sese Seko Kuku Ngbendu wa Za Banga. It belonged to Zairan President of the time, a big lover of big money:

(https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xaf1/t1.0-1/c14.14.172.172/s160x160/282445_138318976249651_3278693_n.jpg)

I remember him since the years when I was working in Uganda. Those were the times of President Idi Amin Dada (the cannibal) - an East African replica of Adolf Hitler. Used to be a "big friend" of the Soviet Union hehe... :

(http://a2.files.biography.com/image/upload/c_fill,g_face,h_300,q_80,w_300/MTE1ODA0OTcxNTM4MDIzOTQ5.jpg)


Title: Re: Lisp in Basic
Post by: JRS on August 03, 2014, 05:29:13 PM
Charles,

Can you split this topic so we can get back to SBLisp and try to get it working?

Thanks!

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 03, 2014, 05:44:18 PM
This isn't an SB Lisp topic! And that's an Open Forum board BTW. :)
Title: Re: Lisp in Basic
Post by: JRS on August 03, 2014, 06:00:52 PM
Okay. It's the SBLisp and FBSL Lisp thread.  :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 03, 2014, 06:22:13 PM
No, actually the first submission was Charles' Lispish effort (http://www.oxygenbasic.org/forum/index.php?topic=1147.msg9967#msg9967). :)

Don't you worry, John. I'm still f... er, ...ighting with the SB Lisp script exactly where I left off yesterday. The Toy interpreter couldn't resist for long and I'm positive SB Lisp won't either.
Title: Re: Lisp in Basic
Post by: JRS on August 03, 2014, 06:54:53 PM
Thanks Mike!

I working on the last round of cleanup where I add spaces between operators and variables. It makes the code much easier to read.

If you can gather a list of fixes to SBLisp since your last release, I can merge them into the version I'm working on. (the one I sent you last night with another level of cleanup)

Keep in mind I'm on the #AllBASIC IRC if need to chat about this.
Title: Re: Lisp in Basic
Post by: JRS on August 03, 2014, 07:20:25 PM
Mike,

Have you run any Lisp benchmarks with FBSL Lisp? I'm curious how it compares with other Lisp Scheme versions. I'm assuming you're running SB on Windows. I'm using the Ubuntu 64 bit version of SB. I also wonder how feature complete the Lisp interpreter is. I wonder if Rob can give your version a try?

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 03, 2014, 08:39:47 PM
Hehe John,

No need for Rob to benchmark FBSL Lisp. He will be able to benchmark SB Lisp instead. Yes, I've killed that beast! :D

There is a deficiency in SB conditionals: it can't tolerate

Code: [Select]
IF INSTR("()'",CURCHAR) OR CURCHAR<=" " THEN
but rather only

Code: [Select]
IF INSTR("()'",CURCHAR)<>0 OR CURCHAR<=" " THEN
That's why both QB45 and FBSL swallowed the script while SB didn't.

Now you can rest in peace (meaning have a good rest ;) ) till tomorrow morning your time. I'm going to grab some sleep too. As soon as I'm awake, I'll clean up all my garbage and post the script here.



See you,
Title: Re: Lisp in Basic
Post by: JRS on August 03, 2014, 08:46:43 PM
Great news Mike.

Keep in mind that SB INSTR() will return a undef not 0 if the match fails.

Quote from: SB Docs
This function can be used to search a sub-string in a string. The first argument is the string we are searching in. The second argument is the string that we actually want to find in the first argument. The third optional argument is the position where the search is to be started. If this argu-ment is missing the search starts with the first character position of the string. The function returns the position where the sub-string can be found in the first string. If the searched sub-string is not found in the string then the return value is undef.

Code: [Select]
p = 0

p = INSTR("ABC","Z")

PRINT p,"\n"

jrs@laptop:~/sb/sb22/sblisp$ scriba testinstr.sb
undef
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: Aurel on August 03, 2014, 08:59:22 PM
Quote
Aurel,
naturlich und selbstverschtendlich = wrong
Natürlich und Selbstverständlich   = correct

yes Peter i know ,i don't have german keyboard   :-\
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 03, 2014, 09:18:46 PM
Quote
Aurel,
naturlich und selbstverschtendlich = wrong
Natürlich und Selbstverständlich   = correct

yes Peter i know ,i don't have german keyboard   :-\

Hi Aurel,

Then IMHO it shoud have been "Natuerlich und Selbstverstaendlich".

Am I correct saying this, Peter?
Title: Re: Lisp in Basic
Post by: JRS on August 03, 2014, 11:02:12 PM
I think I found a typo in the QBLisp program as well.

Code: [Select]
IF PTYPE<>NUMBER OR QTYPE<>NUMBER THEN
  PRINT "ERROR:IN >"
  GOTO HandleError
END IF 
IF PVALUENUMBER OR QTYPE<>NUMBER THEN
  PRINT "ERROR:IN <"
  GOTO HandleError
END IF

I think it should be PVALUE<>NUMBER as that is the only instance of PVALUENUMBER.
Title: Re: Lisp in Basic
Post by: RobbeK on August 04, 2014, 02:16:41 AM
Hi,

I can benchmark against NewLisp script and other interpreted/compiled Lisps if someone likes ....

As for German (attached)  ... in proper Teutonic style ...  (something called Sütterlin ...  )  -- who can read this ?!

Lisp : will be understandable if ...      (defmacro I() 'we )   8)

 

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 02:30:14 AM
Hi Rob,

Need time to read and understand your message: I never thought "e" can be printed as "n" in Gothic! :D

Now urgent: please tell me what (floor -1.6) should return in Lisp?

P.S. So far I got as far as "An meinen Freunden Aurel und Mike : natuerlich und selbverstaendlich ! Uebung macht den Meister !! Rob" (To my friends Aurel and Mike: naturally and evidently! Practice makes one a master!! Rob) :D
Title: Re: Lisp in Basic
Post by: RobbeK on August 04, 2014, 02:35:33 AM
multiple value :

-2
0.399999999999    (<- this value only intercepted by (multiple-value-list  (floor  ....  ))   otherwise it "vanishes" )

best , Rob
Title: Re: Lisp in Basic
Post by: Peter on August 04, 2014, 02:38:45 AM
Quote
Am I correct saying this, Peter?

Yes, that's correct Mike.

Rob translating:

An meinen Freunden Aurel und Mike,
Natürlich und Selbverständlich!

Übung macht den Meister.
Rob

Rob wrote:
To my friends Aurel and Mike,
of course and naturally.

Practice makes perfect!
Rob

Notice: "An meinen Freunden Aurel und Mike" is incorrect,  "An Mein Freund Aurel und Mike"  is correct 
             An Meine Freunde !                                                           
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 02:57:59 AM
@Rob:

Thanks!

Lisp floor() is not correct! This isn't floor() (truncation towards integer), this is round() (arithmetic rounding)! I'm starting to dislike Lisp...


@Peter:

Hi and thanks,

But I think my own transcription and translation are closer to the original!  :P (I missed a capital "F" in "friends" though... :) )
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 03:18:07 AM
Rob,

Thanks for your input but this definition of floor() - and ffloor(), as a matter of fact - is not standard for C, C++, C#, SB, FBSL, etc. etc. etc. In these languages, floor() doesn't truncate towards negative infinity but rather towards zero. It is ceil() that would round 1.6 to 2, and -1.6, to -2.... :(
Title: Re: Lisp in Basic
Post by: RobbeK on August 04, 2014, 03:18:28 AM
Hi Mike :

I did write "selbs.... "     ;)  - an almost verical line ... but the font is not complete -- iir German had a "long" and a "round" s -- to avoid confusion in names as Riefenstahl  ...    is it composed from   riefen + stahl  or  riefens + tahl (?) , they are pronounced differently -- what many do not know is about the "ß"  -- this is a long "s" with a "z"    something as |3  - thus infact writing "groß" in capitals should be GROSZ   ...   like here :
http://www.gentblogt.be/wp-content/uploads/2006/08/20060802_dullegriet1.jpg

-------------------------------------------------------
Function FLOOR, FFLOOR, CEILING, FCEILING, TRUNCATE, FTRUNCATE, ROUND, FROUND

Syntax:


floor number &optional divisor => quotient, remainder

ffloor number &optional divisor => quotient, remainder

ceiling number &optional divisor => quotient, remainder

fceiling number &optional divisor => quotient, remainder

truncate number &optional divisor => quotient, remainder

ftruncate number &optional divisor => quotient, remainder

round number &optional divisor => quotient, remainder

fround number &optional divisor => quotient, remainder



Arguments and Values:


number---a real.

divisor---a non-zero real. The default is the integer 1.

quotient---for floor, ceiling, truncate, and round: an integer; for ffloor, fceiling, ftruncate, and fround: a float.

remainder---a real.


Description:


These functions divide number by divisor, returning a quotient and remainder, such that

quotient*divisor+remainder=number

The quotient always represents a mathematical integer. When more than one mathematical integer might be possible (i.e., when the remainder is not zero), the kind of rounding or truncation depends on the operator:




floor, ffloor

floor and ffloor produce a quotient that has been truncated toward negative infinity; that is, the quotient represents the largest mathematical integer that is not larger than the mathematical quotient.

ceiling, fceiling

ceiling and fceiling produce a quotient that has been truncated toward positive infinity; that is, the quotient represents the smallest mathematical integer that is not smaller than the mathematical result.

truncate, ftruncate

truncate and ftruncate produce a quotient that has been truncated towards zero; that is, the quotient represents the mathematical integer of the same sign as the mathematical quotient, and that has the greatest integral magnitude not greater than that of the mathematical quotient.

round, fround

round and fround produce a quotient that has been rounded to the nearest mathematical integer; if the mathematical quotient is exactly halfway between two integers, (that is, it has the form integer+1/2), then the quotient has been rounded to the even (divisible by two) integer.


All of these functions perform type conversion operations on numbers.

The remainder is an integer if both x and y are integers, is a rational if both x and y are rationals, and is a float if either x or y is a float.

ffloor, fceiling, ftruncate, and fround handle arguments of different types in the following way: If number is a float, and divisor is not a float of longer format, then the first result is a float of the same type as number. Otherwise, the first result is of the type determined by contagion rules; see Section 12.1.1.2 (Contagion in Numeric Operations).


Examples:



 (floor 3/2) =>  1, 1/2
 (ceiling 3 2) =>  2, -1
 (ffloor 3 2) =>  1.0, 1
 (ffloor -4.7) =>  -5.0, 0.3
 (ffloor 3.5d0) =>  3.0d0, 0.5d0
 (fceiling 3/2) =>  2.0, -1/2
 (truncate 1) =>  1, 0
 (truncate .5) =>  0, 0.5
 (round .5) =>  0, 0.5
 (ftruncate -7 2) =>  -3.0, -1
 (fround -7 2) =>  -4.0, 1
 (dolist (n '(2.6 2.5 2.4 0.7 0.3 -0.3 -0.7 -2.4 -2.5 -2.6))
   (format t "~&~4,1@F ~2,' D ~2,' D ~2,' D ~2,' D"
           n (floor n) (ceiling n) (truncate n) (round n)))
>>  +2.6  2  3  2  3
>>  +2.5  2  3  2  2
>>  +2.4  2  3  2  2
>>  +0.7  0  1  0  1
>>  +0.3  0  1  0  0
>>  -0.3 -1  0  0  0
>>  -0.7 -1  0  0 -1
>>  -2.4 -3 -2 -2 -2
>>  -2.5 -3 -2 -2 -2
>>  -2.6 -3 -2 -2 -3
=>  NIL


Side Effects: None.


Affected By: None.


Exceptional Situations: None.


See Also: None.


Notes:


When only number is given, the two results are exact; the mathematical sum of the two results is always equal to the mathematical value of number.

(function number divisor) and (function (/ number divisor)) (where function is any of one of floor, ceiling, ffloor, fceiling, truncate, round, ftruncate, and fround) return the same first value, but they return different remainders as the second value. For example:


 (floor 5 2) =>  2, 1
 (floor (/ 5 2)) =>  2, 1/2

If an effect is desired that is similar to round, but that always rounds up or down (rather than toward the nearest even integer) if the mathematical quotient is exactly halfway between two integers, the programmer should consider a construction such as (floor (+ x 1/2)) or (ceiling (- x 1/2)).

---------------------------------

best , Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 03:28:52 AM
Rob,

I'm aware of your "beta" ("ß") :D and I think this is exactly what I should type as "ss" if I don't have a German keyboard (is it an "azerty" keyboard similar to a French one by the way?)

Now can you please cook up some sort of a very simple loop for this Lisp usable for benchmarking, say, a factorial loop similar to Rosetta Code's

Code: [Select]
(defun fact (n)
  (if (< n 2)
      1
    (* n (fact(- n 1)))))

but using the vocabulary of this particular Lisp? You can find the description here (http://www.cs.rit.edu/~anh/LISPinBASICWebDoc.pdf).

The benchmark should provide for the user input of n if possible (if not then it can be hardcoded) and it should also give the printout of results using (print).

John and I would appreciate it if you could do it for us. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 03:53:56 AM
Notice: "An meinen Freunden Aurel und Mike" is incorrect,  "An mein Freund Aurel und Mike"  is correct

Yes Peter,

I know it. You said I am not your friend any more and un-friended with me (in Facebook lingo). So from your perspective, it is only Aurel who is your friend. Am I correct in my deduction? :(
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 04:11:23 AM
Morning John,

Here comes your SB Lisp. Congrats! :)

(I've used your PVALUE<>NUMBER fixup - it seems reasonable, I've used <>undef following you recommendation, and I've also used INT() for lispish floor() based on Rob's input)

.
Title: Re: Lisp in Basic
Post by: RobbeK on August 04, 2014, 05:21:46 AM
IMHO ..   an meinem Freund then ,  it must be "Dativ" , not ??

Is there a list with functions and macro's of this Lisp -- the pdf gives some examples, but I'm not sure what's inside.
I tried to run the (what was it )   something with pc.exe - but it does not work with my keyboard .

So , answering the keyboard question :  it's Belgian   (in DOS   keyb be ), something rare which tries to mix a French AZERTY with a German (Dutch, French and German are the official languages here -- is the sequence of studying at school (except some Latin and old Greek is inserted before the German (for those who passed "the test" -- promoted and handled by the diosece -- especialy the "Societas Jesu" were interested in future intelligentsia under their flag  >:(   -- it's a looong time ago now !!

best Rob

gross (short o)  grosz (long o)  -- not sure Gross exists in German , normally it should mean a dozen of dozens (12x12)
the big gun attached (I had to post twice previously ..)

addendum :
---------------

if possible, I suggest next -- a lispish way to do the Fibonacci 

(define (fib x)
  (let ((nr '(0 1)))
   (dotimes (i x t)
     (setq nr (list (nth 1 nr) (+ (nth 0 nr) (nth 1 nr)))))
 (nth 1 nr)))

-- (fib 1000) in NewLisp is still below 0 mSec ..  question thus , do your Lisps have extended (big) integers like Common Lisp and NewLisp (and PicoLisp) ??

if this is ok, I'll give the Common Lisp version (Newlisp uses somewhat of Scheme like (define ( x y .... ) ... ) i.o. (defun x (y ... ) ...)



.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 04, 2014, 06:13:55 AM
Quote
(defun fact (n)
  (if (< n 2)
      1
    (* n (fact(- n 1)))))

In Lispish, a simple looping operation can be done by using (iter n) instead of recursion.

Thus n factorial:
Code: [Select]
( let n 5 )
( * n ( iter n ) ) ; expands to ( * 5 4 3 2 1 )
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 06:51:50 AM
Rob,

IMHO ..   an meinem Freund then ,  it must be "Dativ" , not ??
I guess that's the question for Peter, not for me. ;)

Quote
Is there a list with functions and macro's of this Lisp -- the pdf gives some examples, but I'm not sure what's inside.
Unfortunately, the PDF is all we have. Its list of features is exhaustive for this implementation. Thanks for your code snippets anyway but they don't seem to go well with this implementation due to the lack of features.

Quote
I tried to run the (what was it )   something with pc.exe - but it does not work with my keyboard .
Not sure exactly what you mean but if you want to run this Lisp as an executable under Windows, you can use its FBSL adaptation (http://www.oxygenbasic.org/forum/index.php?topic=1147.msg10076#msg10076). It wasn't optimized for speed and carried a lot of unnecessary rubbish like if asc("a") < asc("b") in place of if "a" < "b" just to be on the safe side while debugging, but it will work.

Quote
gross (short o)  grosz (long o)  -- not sure Gross exists in German , normally it should mean a dozen of dozens (12x12)
Yes, understood. I was just talking about the absence of a German keyboard layout (have a look at a QWERTY keyboard (http://www.microsoft.com/enable/images/products/kbqwerty.gif)), in which case the typist is supposed to substitute a "beta" glyph with a double "s" -> "ss". At least this is what my wife's telling me. She's a Belarusian but she grew up in East Berlin and she also used to be a certified typist in her greener years.

Quote
the big gun attached (I had to post twice previously ..)
Yes, I got the SZ written there. BTW that one wasn't of the largest caliber actually. Царь-пушка (The Tzar Gun) in the Moscow Kremlin seems to be somewhat more impressive. :)

(http://www.etovidel.net/appended_files/big/4ecf4d93a0759.jpg)


Hi Charles,

There's no (iter) in this Lisp but there's a (for-each) iterator in it. OK I'll try to make out what is what in it myself. Anyway it was me that succumbed to this venture... :)

P.S. This thing uses a Scheme, not Common Lisp, syntax...
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 08:03:40 AM
Hehehe,

Here's its syntax to calculate the factorial of 8 recursively. :D

Use (factorial X) in the function call to calc the factorial of any other X.


P.S. And I'll be d*mned, it does it instantly!



.
Title: Re: Lisp in Basic
Post by: JRS on August 04, 2014, 08:06:57 AM
Quote from: Mike
John and I would appreciate it if you could do it for us.

It doesn't seem to work in SBLisp.

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](defun fact (n)
1]  (if (< n 2)
2]     1
2]    (* n (fact(- n 1)))))
ERROR: UNBOUND VARIABLE
0]
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 08:17:25 AM
Hi John,

Wrong syntax! Repeat 2: This thing uses Scheme, not Common Lisp, syntax : End Repeat

:D
Title: Re: Lisp in Basic
Post by: JRS on August 04, 2014, 08:31:09 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)
4]    1
4]    (* n (fractorial (- n 1)))))))
FACTORIAL
0](factorial 8)
ERROR: BAD TYPE IN CAR
0]

Not having much luck with SBLisp.  :-\
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 08:36:21 AM
There's a typo in your input, John. It should be (<= n 0) rather than ((= n 0). :)


AND IT SHOULD BE FACTORIAL, NOT FRACTORIAL!
Title: Re: Lisp in Basic
Post by: JRS on August 04, 2014, 08:43:17 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 (fractorial (- n 1)))))))
FACTORIAL
0](factorial 8)
ERROR: IN <
0]

My first attempt was using your FBSL screen shot code which seems to work for you. The last correction didn't help.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky 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)))))))
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 04, 2014, 08:54:47 AM

How would you make an average function, Mike? - taking a variable number of params.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky 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?
Title: Re: Lisp in Basic
Post by: JRS 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!
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky 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.
Title: Re: Lisp in Basic
Post by: Charles Pegge 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!

Title: Re: Lisp in Basic
Post by: JRS 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.
Title: Re: Lisp in Basic
Post by: RobbeK 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

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky 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.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky 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
Title: Re: Lisp in Basic
Post by: Charles Pegge 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
Title: Re: Lisp in Basic
Post by: JRS 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.

Title: Re: Lisp in Basic
Post by: RobbeK 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




Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 10:10:14 AM
Charles,

Here's a direct link (http://www.cs.rit.edu/~anh/LISPinBASICWebDoc.pdf).

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.
Title: Re: Lisp in Basic
Post by: JRS on August 04, 2014, 10:18:46 AM
Here is my task list for the SBLisp version.


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

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 10:36:32 AM
Thanks John.

I'm not planning to extend the FBSL version beyond its original scope. I guess I'll just post it raw on the forum together with its PDF like I did with Ed Davis' Toy interpreter. So I think you should be the project's frontman in this respect. On my behalf, since this version is more Scheme oriented than anything else, I'd suggest looking through Scheme's standard vocabulary and trying to reproduce it as fully as possible. Once the basic interface is implemented, SB "deviationisms" may be added for seamless interaction with the host language.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 04, 2014, 10:58:58 AM
Rob, I will try to get an updated Lispish version out tonight - adding in some more maths functions.
Title: Re: Lisp in Basic
Post by: JRS on August 04, 2014, 11:04:17 AM
Quote
Rob, I will try to get an updated Lispish version out tonight - adding in some more maths functions.

@Charles - What version of Lisp is the O2 version based on? Is it possible I can incorporate your additions into the SBLisp version or would that break the Scheme syntax?

Title: Re: Lisp in Basic / common lisp specs - common lisp 2nd edition
Post by: RobbeK on August 04, 2014, 11:25:30 AM
CL Hyper Spec   (what i use when looking up something )

Some background info on Common Lisp. (not Scheme (also a Lisp but not Common Lisp)).

best Rob



.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 04, 2014, 11:27:23 AM
John, I don't think they can be mixed safely at this stage of development. It is quite experimental, and I am mainly on a semantics discovery expedition with this project, hence my cavalier disregard of conventional LISP :)

The source  and test codings: projectsA/LeanLisp
Title: Re: Lisp in Basic
Post by: Aurel on August 04, 2014, 12:32:10 PM
well
mike ..i really doubt that your real name is MIKE
because there is no such a neme i in ANY slavonic- slovenian -bela- bjelo (white)
rusijan names...right?

Peter
Natürlich und Selbverständlich
WRONG
Natürlich und Selbstverständlich
right?

anyway LISP ...pih :P
Title: Re: Lisp in Basic
Post by: JRS on August 04, 2014, 12:49:14 PM
Seems Aurel is on the war path again.

Why don't you try that with Charles and see how long you last.

Personally, I'm sick and tired of all your negativeness with everywhere you post and no longer wish to share in your misery.
Title: Re: Lisp in Basic
Post by: RobbeK on August 04, 2014, 01:03:08 PM
Hi Aurel,

Rob or Bob is not a Flemish name either -- but that's the way I call myself (for my Russian friends it has something of Mr Bean (the bob)) - but that's very amusing ..

"Be what you would seem to be - or, if you'd like it put more simply - never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise.” 
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 01:14:16 PM
Aurel,

"When I was younger so much younger than today" (c), almost every non-Russian Slav was able to understand, at least partially, the Russian language. Regretfully, Russians in their turn have never given a damn to understand anything but Russian. Russian is my mother tongue though I am a Ukrainian by nationality and blood, and though for over 40 years I've been and still am living in the Republic of Belarus and am the bearer of a Belarusian passport.

Belarus has two official languages, Belarusian and Russian.

Thus my full name is:

Мiхаiл Мiхайлавiч Лабко-Лабаноўскi - in Belarusian (given name / parental name / double surname as per my passport)
Михаил Михайлович Лобко-Лобановский - in Russian (same)
Михайло Михайлович Лобко-Лобановський - in Ukrainian (same as per my Ukrainian matriculation card)
Michael Lobko-Lobanovsky - in English (given name / double surname as per my passport for foreign travel)
Mike Lobanovsky - in English (informal diminutive of given name / single surname for casual addressing)

I have never been too intravert or touchy to hide my origin or identification behind artificial nicknames. I have nothing to hide from, or be ashamed of in, people's eyes. :)

I always wondered what E and V initials stand for in Charles' name? :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 01:22:59 PM
On the other hand, John, if there were no such, er, trolls as Aurel, and no such epic flooders as Mike and John, and no such volatile and flamboyant artistic souls as Peter, this place would look pretty dull for Charles and Rob with their Lisps and higher maths routine.

:D
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 01:24:11 PM
"Be what you would seem to be - or, if you'd like it put more simply - never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise.”

Isn't that a real mighty piece of wisdom? ;D A British sterling way of putting things is what I call it. ;D
Title: Re: Lisp in Basic
Post by: Aurel on August 04, 2014, 01:28:23 PM
Quote
Seems Aurel is on the war path again.
no..no...i am not...
if you think that way ..this just explain how much you are limited on some things.

Mike ..
of course i understand.... ;)
and thank on explanation  :)
sooo on my home languge your name is Mihael
 :)
Title: Re: Lisp in Basic
Post by: Aurel on August 04, 2014, 01:32:32 PM
anyway
what a fuccck is troll ...there is no such a stupid or limited word in my language.
i really ..really cannnot figured who is the biggest "troll" on the internet than you JRS
 :P
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 01:39:33 PM
No Aurel,

Such characters as John or me are in fact serving a different purpose. We dilute your negative trolling and hatred with our pseudo-constructive and sometimes even positive flood of irrelevant data and minor personal deviations. :)

Yours,

Mihael :)
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 04, 2014, 01:44:16 PM

You may rediscover all your previous  identities here :)

http://www.innerjourneys.co.uk/past-life-recording.html
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 01:51:27 PM
LOL is that a kind way to shut me up?! I'm *terribly* susceptible to such things! I would've been sleeping in a few more seconds hadn't I shut that page NOW!

;D
Title: Re: Lisp in Basic
Post by: Aurel on August 04, 2014, 01:52:56 PM
Quote
No Aurel

No Mike
You are not JRS...you are not LIAR and you are very open in any discusion
BUT your friend J ...come on  ::)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 01:55:01 PM
OK Charles,

I beg your pardon. Matter was I'd just come from Facebook and I couldn't switch over to a different manner of conversation. I'm sorry.

I'm shutting up. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 01:59:18 PM
Quote
No Aurel
No Mike
You are not JRS...you are not LIAR

Come on Aurel, let's try to be constructive and positive for a change. And let bygones be bygones (look it up in Google Translator, please). We're not home in the kitchen. We are out in the public chez Charles.

We have personal messaging if we want to be rude, and we can even sometimes *delete our messages* when we realise we might've been just a little too tough on one another. :)
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 04, 2014, 02:05:15 PM

(http://asciiville.com/media/cartoons/past-life-regression-testing.jpg)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 02:14:26 PM
LOL exactly! :) Big up, as they say on FB! :)
Title: Re: Lisp in Basic
Post by: JRS on August 04, 2014, 03:13:41 PM
I posted to Bitbucket (https://bitbucket.org/ScriptBasic/sblisp) a beta version of SBLisp.

Scheme Basics (http://courses.cs.washington.edu/courses/cse341/03wi/scheme/basics.html)

@Rob - If you have time to do a little beta testing that would be great.

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](quit)
Bye!
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: JRS on August 04, 2014, 04:22:39 PM
Mike,

I thought that you were going to use the SB FIX() function for DoFlr (Floor)

Code: [Select]
DoFlr:
  ptype = qtype
  pvalue = qvalue
  bsd += 1
  GOSUB Car
  IF rtype = number THEN
    rvalue = INT(rvalue)
    bsd -= 1
    RETURN
  END IF
  PRINT "ERROR: In FLOOR\n"
  GOTO HandleError

Scheme vs. Common Lisp
Code: [Select]
What Common Lisp has got:         What Scheme has got:

Much better developed standard    SLIB + SRFI's + a hundred little
libraries                         libs that each do things differently
                                  and aren't very standardized.

   (Arguably Scheme is the place where new ideas fight for mindshare
    and prove themselves - but the fights and the multiplicity
    of contenders commits most code to one idea or another and
    limits the code's interoperability, longevity, and/or
    portability.)


A well-defined comprehensive      A well-defined minimal spec plus
spec and several implementations  dozens of variously comprehensive
which provide some extensions.    implementations. 

Escaping continuations only.      Fully reentrant continuations.
                                  Scheme just wins on this point.

   (I have heard the arguments about whether fully reentrant
    continuations are worth the cost of stack copying, or the
    cost of heap-allocating and garbage collecting invocation
    frames.  I don't care.  I'm just noting here that you can
    do a *LOT* of things with them that are hard to do without
    them.)

Lots of iterative constructs      Memory-safe tail recursion avoids
                                  the need for iteration syntax. 
                                  There's a looping construct, but
                                  it's more complicated than tail
                                  recursion so hardly anyone uses it.
                                  If you care for them, you can
                                  roll your own using continuations.

Both Lexically and Dynamically    Lexical scope only, per the standard.
scoped special vars.  Common      Dynamically scoped vars are provided
Lisp just wins on this point.     by some implementations as an extension
                                  but code using them is not portable.

     (I have heard the arguments about whether Dynamic scoping
      is or is not a Bad Idea in the first place.  I don't care.
      I'm just noting that you can do things with it that you
      can't easily do without it.)


C numeric types plus bignums      Implementation-defined numeric types,
and complex nums, but no exact/   in some implementations failing to
inexact distinction.              include bignums or complex nums.  An
                                  exact/inexact distinction is required
                                  by the standard but properly implemented
                                  in only about 3/4 of scheme systems.
                                  In a good implementation, numerics
                                  (capabilities and correctness) are
                                  better than most CLs; on average,
                                  they are worse.

Optional type declarations        Optional type declarations provided
allow blazing fast numeric        by a few implementations as extensions.
code to skip typechecking.        Code using them is nonportable.  Some
Common Lisp just wins on numeric  implementations provide blazing speed
calculation speed.                but generally at the expense of numeric
                                  type richness and/or standard
                                  conformance.

Signals and conditions, catch     Roll your own using fully reentrant
and throw.                        continuations, or use any of several
                                  libraries.

CLOS                              Roll your own objects using closures
                                  and macros, or any of several OO
                                  libraries. TinyCLOS and Meroon are
                                  the most popular.

Well-defined standard module      At least three competing well-defined
system.  Common Lisp just wins    module systems which it's a pain in
on this point.                    the butt to move modules between.
                                  (or roll your own using scope, macros,
                                  and/or preprocessing code).

Readtables for low-level          Implementation-defined means of doing
macrology. Common Lisp wins       low-level macrology - none of it
here.                             portable.

gensym tricks to avoid implicit   hygienic macros with define-syntax and
variable captures in high-level   syntax-case.  You *can't* capture a
macros.                           variable in a macro except explicitly.

    (Different people claim this as a "win" for both languages.
     I don't care.  There is little difference in what I can do
     with it, nor in how hard it is to do it, so I'm not the guy
     to judge a winner here.)

One-argument eval assumes         environment specifier is second arg to
environment                       eval, allowing access to multiple
                                  environments.  Scheme just wins here.

Lambda syntax supports keyword    Available as add-on library developed
arguments & default vals for      using macros, but widely ignored.
optional arguments.

Symbols have properties,          Variables have values and also names.
including but not limited to      The names are lexically indistinguishable
function value and data value.    from symbols but the value of a variable
                                  is not a property of its name symbol. 
                                  Property lists are an extension
                                  provided by relatively few schemes.

Native hash tables.               Library hash tables.

Well-defined means of doing       A fragile hack that depends on common
binary I/O.  Common Lisp just     character encodings and/or assumption
wins here.                        that character ports act as byte ports.


Assertions.  Common Lisp just     In scheme you have to do this as two
wins here.                        macros; one for development, that signals
                                  an error if the condition isn't true, and
                                  one for production code which "expands"
                                  into nothing and gets out of the way.
                                  The compiler will not use your assertions
                                  to produce better code.


Large runtime environment         Small runtime environment, easily
                                  embeddable.  Scheme wins here.

Based on the above it seems that Scheme was the better choice to build on top of SB. Maybe the deficiencies in Scheme can be compensated for by SB in a seamless way.
Title: Re: Lisp in Basic
Post by: JRS on August 04, 2014, 05:33:32 PM
In my search to find the gold standard of Scheme interpreters, I kept running into MIT/GNU Scheme (http://www.gnu.org/software/mit-scheme/). I downloaded the Unix 64 bit source and built it from scratch.

Code: [Select]
jrs@laptop:~$ mit-scheme
MIT/GNU Scheme running under GNU/Linux
Type `^C' (control-C) followed by `H' to obtain information about interrupts.

Copyright (C) 2014 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Image saved on Saturday May 17, 2014 at 2:39:25 AM
  Release 9.2 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || Edwin 3.116

1 ]=> (define factorial (lambda (n)
(if (<= n 0)
1
(* n (factorial (- n 1)))))))

;Value: factorial

1 ]=> (factorial 8)

;Value: 40320

1 ]=> (quit)

[1]+  Stopped                 mit-scheme
jrs@laptop:~$


Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 05:40:20 PM
John,

1. Following a discussion with Rob much earlier in this thread (I think you were still having you rest then) and also based on some Lisp math specs he cited there, Lisp's concept of floor() and ceil() doesn't obey C, C++, C#, SB, FBSL, etc. rules of numeric rounding. So the L-i-B author was correct in choosing INT() for DoFlr which is the closest approximation that a BASIC can get. Lisp's floor() always rounds down to negative infinity - something which isn't available in SB or FBSL (or in C they are both written in, for that matter).

So I removed Floor() from the FBSL version too for the same reason.

2. Is the table your own investigation or someone else's?

3. Nice! Now you have a test bench to verify SBLisp against.


P.S. John, I'm getting off the air for tonight now if you don't mind. If you have any comments or questions, please post them here and I'll come back with my answers tomorrow morning (local time). See you tomorrow.

Title: Re: Lisp in Basic
Post by: JRS on August 04, 2014, 05:52:50 PM
Quote
. Is the table your own investigation or someone else's?

Please, I can hardly spell Lisp.  ;D
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 04, 2014, 05:57:13 PM
I can't either (too sleepy). :)

(http://www.fbsl.net/phpbb2/images/smilies/icon_ml_gnight.gif)
Title: Re: Lisp in Basic
Post by: JRS on August 04, 2014, 09:33:29 PM
I don't think file loading is working.

(load "myfunc.scm")

One thing I found is the filename is being UCASE() which needs to be addressed but that doesn't account for rhe bad symbol error message. It never gets to the SB OPEN statement.

Attached is a screen shot of debugging this with the new SB IDE/Debugger.


.
Title: Re: Lisp in Basic
Post by: RobbeK on August 05, 2014, 01:15:54 AM
@ John

I'll try to run some things from your app. 

As for the Japi --  no news, no answers , the complete NIHIL from the Java front ...

As for Scheme ,  next may be worth a look ,  I know it runs those Fu-script in the GIMP graph. editor (and does a good job).
http://tinyscheme.sourceforge.net/home.html
(no experience with it though)

@Mike,

Seems Belarussian solved the problem of the intonations on the "o" (compared with Russian)  ..  so guessing "milk" in belarus 2 "a"s and one "o" ??

best Rob

Addendum  -- to list or not to list ??
--------------------------------------------

attached :  Lisp working with a list and doing the same with 2 variables ( my idea : if you want Lisp give the speed of C , it looks (with other syntax and "nomenclature") likes C    :-\ )

(done in interpreted GNU CL  -- a fork from Kyoto Common Lisp )  -- when compiled both give 0 mSec ..
it then generates a gazonk - file ???    Mike , any one else what is a gazonk ???   )




.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 05, 2014, 06:05:03 AM
Hi John,

Sure it doesn't. Please do the following:

-- goto line 101 in lisp.sb and change "QUOTES" to "QUOTE" (that's a typo after my autoreplacement of QUOTE for QUOTES because Quote() is an FBSL intrinsic function);
-- create a file "fact.lisp" with the following contents (it should also include the "function" call proper for it to be executed rather than typed in as in an interactive mode):
Code: [Select]
(define factorial (lambda (n)
(if (<= n 0)
1
(* n (factorial (- n 1)))))))

(factorial 8)
-- do not use (load "fact.lisp") - this isn't a proper syntax for Lisp. You should use (load (quote fact.lisp)) instead.

The file will load in both FBSL and SB:

-- FBSL prints the entire file, executes the "function" call, and prints out the result and a "T" symbol (=TRUE in Lisp) that signifies successful comletion of the task (see the appended screenshot 1).

-- SB would however print the first line only and then break on a file read error (see screenshot 2).

I don't know the exact cause of the error; perhaps your SB syntax for sequential line read from a text file isn't correct. Please try and fix it yourself. FBSL uses a word-for-word translation of both QB45 and SB syntax but with its own keywords, which means the algo as a whole is correct.

[EDIT] Goto line 693 in lisp.sb and change the If block that you'll find there, to the code below. It'll fix your read/execute problems:

Code: [Select]
IF NOT EOF(LispFileNum) THEN
LINE INPUT# LispFileNum, I
I = CHOMP(I)
PRINT I, "\n"
IPOS = 1
END IF

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 05, 2014, 06:23:02 AM
Hi Rob,

Both Belarusian and Russian languages would reduce an unaccented "o" to "a" so that "milk" would be pronounced as мааО.

But while the Russian grammar preserves the original orthography of root vowels irrespective of the position of accent in a word, the Belarusian orthography professes the write-as-you-hear approach so that all "o"'s are turned into "a"'s unless accented.

Hence Russian молоко turns into Belarusian малако, and the exact same phenomenon can be seen in the orthography of my own name.

The Ukrainian language does not know the reduction of vowels so "milk" will be both pronounced and spelt as молоко irrespective of the accent.


P.S. Oh, I missed your last question: no, "gazonk" doesn't ring the bell for me; it sure doesn't have any Slavonic roots in it. Isn't it coming from a Kyoto fork of the language?

(http://images.nationalgeographic.com/wpf/media-live/photos/000/300/cache/alley-kyoto_30033_600x450.jpg)
Title: Re: Lisp in Basic
Post by: JRS on August 05, 2014, 08:48:00 AM
Thanks Mike !!!

So you don't think there is a UCASE() issue with the filename being passed?  I was using Dave's debugger and as it was parsing the load command, the resulting string was upper cased and escaped with \" characters. You got it to work so I must be seeing things.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 05, 2014, 09:02:02 AM
Bingo! :)

Actually everything that's a SYMBOL is uppercased before it goes into the hash table. It helps analyse the tokens char by char (reduces the range of possible cases to consider). That's how it ought to be.

Case sensitivity of Linux file names is another matter. I'm using a 32-bit Windows scriba.exe for debugging so I don't know how a Linux scriba handles this issue and if it requires a verbatim LispFileName or not. Please try and change lowercase fact.lisp to Fact.lisp but leave (load (quote fact.lisp)) unaltered. This check will tell you if the linuxoid SBLisp requires an exact match of filename characters.
Title: Re: Lisp in Basic
Post by: JRS on August 05, 2014, 09:48:30 AM
Okay. Thanks for the tips.

Here is an interesting tutorial on learning programming using Scheme.

How to Design Programs (http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-1.html)

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 05, 2014, 10:27:02 AM
A Lamer's Guide to SBLisp! :D

And as an immediate exercise for you as the developer, I'd suggest adding a valid ; comment marker to SBLisp. It shouldn't be too difficult to implement and it would also stimulate your parental instincts. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 05, 2014, 12:07:51 PM
FYI:

FBSL LISP in BASIC translation (http://www.fbsl.net/phpbb2/viewtopic.php?p=10561#p10561) has been published on the FBSL site.
Title: Re: Lisp in Basic
Post by: JRS on August 05, 2014, 05:05:26 PM
Yep. I'm going to have to deal with the UPPER case issue on Linux.

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](load (quote factfunc.scm))
FACTFUNC.SCM  1
(0): error &H16:The file can not be opened.
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 05, 2014, 05:07:32 PM
... as it was parsing the load command, the resulting string was upper cased and escaped with \" characters.

Sorry John,

I missed this question somehow. No, you weren't seeing things. As the LISP parser was trying to chew the "filename.ext" string, the SB parser was dealing with its individual characters. Presumably, a \" escape is its internal representation of the DQ glyph similar to how it is expressed within a C string (SB is written in C). This is because strictly speaking, the debugger doesn't respond to what goes on in your SB "program" but rather to what happens in its underlying machine code compiled from the C language sources.

Now that we know SBLisp doesn't recognise enquoted strings, we aren't using DQ's and you won't see such escaped artifacts in your debugger any more.

This implementation of the language doesn't distinguish between numeric data and enquoted string data. It only distinguishes between evaluatable/executable statements, variables, and data literals as a whole. A data literal is an entity enclosed in parentheses and denoted with a quote marker in between them. Data literals are never executed or evaluated and their corresponding parentheses don't denote a command but rather the bounds (scope) of the literal.

That said, (load (quote filename.ext)) can be understood as a command to accept filename.ext as a literal non-evaluatable non-executable piece of data and apply it to load as an argument for execution, or in simpler words, as a command to load filename.exe.

Pooh! :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 05, 2014, 05:10:33 PM
Yep. I'm going to have to deal with the UPPER case issue on Linux.

Be forewarned you're gonna lose case insensitivity of the entire language if you just remove the UCASE() conversion blindly.  :-\
Title: Re: Lisp in Basic
Post by: JRS on August 05, 2014, 05:15:03 PM
Agreed but isn't the symbol (LOAD) known at that point and I can handle it with a IF?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 05, 2014, 05:20:59 PM
Strictly speaking, it is. But to intercept a LOAD XXXXX[.XXX] sequence, you will have to constantly monitor at once the contents of at least one current element of two arrays - the code stack array and the data stack array. It will be very, very burdensome for an interpreted Linux SBLisp. You will be losing the benchmark race to FBSL and Windows SBLisp by at least two fold. ;)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 05, 2014, 05:23:59 PM
I have a palliating proposition. ;)
Title: Re: Lisp in Basic
Post by: JRS on August 05, 2014, 05:44:33 PM
I'm all ears.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 05, 2014, 06:28:24 PM
Sorry, I've been held in an iron embrace of HAL 9000 for awhile.

So, since user input is a millenium-long operation from the CPU perspective, it would be reasonable to squeeze the entire LispFileName/filename.ext evaluation procedure into the LispOpenInputFile: block. Here's where you can afford a SELECT CASE or IF block (or a set of labeled subsections) of virtually unlimited length without any perceptible lag.

Let the LispFileName symbol be stored as it is now, in uppercase. Use SELECT CASE or IF (or a set of labeled subsections) within LispOpenInputFile: to transform the uppercase LispFileName into all sorts of imaginable spelling. Try all uppercase; all lowercase; lower for name and upper for extension and vice versa;  check for an underscore in the name and try mixed (camel) case for its parts in every combination; check for a space and retry the preceding combinations; etc. etc. etc. - all of this while trapping the error &H16:The file can not be opened. with SB's own ON ERROR ... to redirect execution to the next option in your SELECT CASE or IF chain (or a set of labeled subsections). And finally, let CASE ELSE or ELSE or trailing subsection label throw the &H16 exception.

Subjectively, this will be executed instantly and it won't affect the interpreter's speed in any way because it will be a one-time action.
Title: Re: Lisp in Basic
Post by: JRS on August 05, 2014, 06:58:41 PM
All good points. Let me take a look at the easiest and fastest way of fixing this and put a note in the code to come back to it.  :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 05, 2014, 07:05:58 PM
OK John. Going off to bed too. See you tomorrow.
Title: Re: Lisp in Basic
Post by: JRS on August 05, 2014, 07:33:21 PM
For now, ALL loaded SBLisp scripts must have the filename in UPPER CASE.

Wasn't that easy?  ;D

After trying it ...

FYI: Latest code on Bitbucket.

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](load (quote FF.SCM)
1]
ERROR: Read.
0]

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

(factorial 8)

Well, at least we got by the SB OPEN.

Title: Re: Lisp in Basic
Post by: JRS on August 05, 2014, 07:49:49 PM
Quote from: Pritchard (aka Moe) - FreeBASIC forum
Not bad source at all. LISP is simple, but I still wouldn't know how to implement it in QBASIC

Maybe the other remaining stooge will clue him in.  :P

@Pritchard - All I'm hearing from the FB boys is swishing sounds.  ;D
Title: Re: Lisp in Basic
Post by: JRS on August 05, 2014, 09:33:18 PM
Testing against the gold standard.

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ mit-scheme
MIT/GNU Scheme running under GNU/Linux
Type `^C' (control-C) followed by `H' to obtain information about interrupts.

Copyright (C) 2014 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Image saved on Saturday May 17, 2014 at 2:39:25 AM
  Release 9.2 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || Edwin 3.116

1 ]=> (load (quote FF.SCM))

;The object ff.scm, passed as an argument to merge-pathnames, is not a pathname.
;To continue, call RESTART with an option number:
; (RESTART 1) => Return to read-eval-print level 1.

2 error>

What? The file name is FF.SCM not ff.scm.

You would think someone other than Mike, Charles or Dave would have come forward an admitted to using SB.


.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 06, 2014, 06:41:18 AM
Hi John,

For now, ALL loaded SBLisp scripts must have the filename in UPPER CASE.

Wasn't that easy?  ;D
Well, this is much more restrictive than the palliation that I suggested. Now SBLisp and "the gold standard" are worthy of one another - both are dumb as hell.

Quote
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
0](load (quote FF.SCM)
1]
ERROR: Read.
0]
Wait wait, but where's the closing parenthesis, may I ask?

Quote from: BITBUCKET
GetLine:
  IF lispfilenum = 0 THEN
    PRINT LTRIM(FORMAT("%~##~", oparen)), "]"
    LINE INPUT ibuf
    ibuf = CHOMP(ibuf)
    ipos = 1
  ELSE
    IF NOT EOF(lispfilenum) THEN
      LINE INPUT# lispfilenum, ibuf
      PRINT ibuf
      ipos = 1
    END IF
  END IF
  bsd -= 1
  RETURN
John, you're downright ignoring my messages (http://www.oxygenbasic.org/forum/index.php?topic=1147.msg10191#msg10191):

Code: [Select]
IF NOT EOF(LispFileNum) THEN
LINE INPUT# LispFileNum, I
I = CHOMP(I)
PRINT I, "\n"
IPOS = 1
END IF
Please correct the Bitbucket sources and get your linuxoid SBLisp up and running at last. ;)

Quote
Well, at least we got by the SB OPEN.
Not "we" but "I". As for me, I got the Windows scriba.exe+lisp.sb reading and executing LISP files 48 hours ago. :)
Title: Re: Lisp in Basic
Post by: JRS on August 06, 2014, 07:29:55 AM
Quote
Not "we" but "I". As for me, I got the Windows scriba.exe+lisp.sb reading and executing LISP files 48 hours ago.

I'm jelous. 
Title: Re: Lisp in Basic
Post by: RobbeK on August 06, 2014, 09:38:11 AM
Ah, thanks Mike  ...

Yes, it was a deduction from your name in belarusian ..  did not know about the Ukranian either .
(the only thing I knew was that very rarely the Arsenal plant (cameras and lenses) put Киïв on their gear and not Киев  .. very rare and expensive now .. collector's items ...  )

gazonk...   heart it before, but don't remember ..   (1/1000000 th of a sec the Russian word for spy-glass came into my mind -- of course not related   8) )

best Rob
Title: Re: Lisp in Basic
Post by: JRS on August 06, 2014, 09:45:41 AM
Getting closer.

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](load (quote FF.SCM))
FF.SCM  1
(define factorial (lambda (n)
(if (<= n 0)
1
(* n (factorial (- n 1))))))
FACTORIAL

(factorial 8)
40320


ERROR: Read.
ERROR: Problem in file FF.SCM
0]

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

(factorial 8)

If I remove all blank lines from the end of the script except one, this is what I get.

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](load (quote FF.SCM))
FF.SCM  1
(define factorial (lambda (n)
(if (<= n 0)
1
(* n (factorial (- n 1))))))
FACTORIAL

(factorial 8)
40320

ERROR: Problem in file FF.SCM
0]

Title: Re: Lisp in Basic
Post by: JRS on August 06, 2014, 10:09:50 AM
Success!

It seems you can't have any blank lines at the end of the script.

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](load (quote FF.SCM))
FF.SCM  1
(define factorial (lambda (n)
(if (<= n 0)
1
(* n (factorial (- n 1))))))
FACTORIAL

(factorial 8)
40320
T
0]
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 06, 2014, 10:36:47 AM
Congrats John! :)

FYI:

1. An alternative way to denote literals is to prepend them with a single quote (apostrophe) '. Thus

Code: [Select]
(load (quote test.lisp))
may be written as

Code: [Select]
(load 'test.lisp)
to the same effect.

2. There's no way to print a new line or a space now. I'm using

Code: [Select]
(print '_)
for a space but I don't know how to enforce a new line. Seems like the PRINT procedure needs to be improved on. Also, currently there's no way to suppress printed output of intermediate evaluations so there may be meaningless garbage in the console.
Title: Re: Lisp in Basic
Post by: JRS on August 06, 2014, 10:49:17 AM
It would be great to get this stuff posted to the Bitbuket issue tracker.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 06, 2014, 10:54:05 AM
wat?

:D

A tip:

save the following as rectest.lisp

Code: [Select]
(define rectest (lambda (x)
(cond ((<= x (* 1000)) (print x) (print '_) (rectest (+ x 1))))
))

(rectest 1)

and watch LISP recursion in your console. Note also the GC START GC DONE occurences at the points where LISP auto-garbage-collects its memory for deeper and deeper recursion. :)
Title: Re: Lisp in Basic
Post by: JRS on August 06, 2014, 11:00:55 AM
Cool !

It seemed to execute almost instantaneously.

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](load (quote RECTEST.LISP))
RECTEST.LISP  1
(define rectest (lambda (x)
(cond ((<= x (* 1000)) (print x) (print '_) (rectest (+ x 1))))
))
RECTEST

(rectest 1)
1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39_40_41_42_43_44_45_46_47_48_49_50_51_52_53_54_55_56_57_58_59_60_61_62_63_64_65_66_67_68_69_70_71_72_73_74_75_76_77_78_79_80_81_82_83_84_85_86_87_88_89_90_91_92_93_94_95_96_97_98_99_100_101_102_103_104_105_106_107_108_109_110_111_112_113_114_115_116_117_118_119_120_121_122_123_124_125_126_127_128_129_130_131_132_133_134_135_136_137_138_139_140_141_142_143_144_145_146_147_148_149_150_151_152_153_154_155_156_157_158_159_160_161_162_163_164_165_166_167_168_169_GC START GC done.
170_171_172_173_174_175_176_177_178_179_180_181_182_183_184_185_186_187_188_189_190_191_192_193_194_195_196_197_198_199_200_201_202_203_204_205_206_207_208_209_210_211_212_213_214_215_216_217_218_219_220_221_222_223_224_225_226_227_228_229_230_231_232_233_234_235_236_237_238_239_240_241_242_243_244_245_246_247_248_249_250_251_252_253_254_255_256_257_258_259_260_261_262_263_264_265_266_267_268_269_270_271_272_273_274_275_276_277_278_279_280_281_282_283_284_285_286_287_288_289_290_291_292_293_294_295_296_297_298_299_300_301_302_303_304_305_306_307_308_309_310_311_312_313_314_315_316_317_318_319_320_321_322_323_324_325_326_327_328_329_330_331_332_333_334_335_336_337_338_339_GC START GC done.
340_341_342_343_344_345_346_347_348_349_350_351_352_353_354_355_356_357_358_359_360_361_362_363_364_365_366_367_368_369_370_371_372_373_374_375_376_377_378_379_380_381_382_383_384_385_386_387_388_389_390_391_392_393_394_395_396_397_398_399_400_401_402_403_404_405_406_407_408_409_410_411_412_413_414_415_416_417_418_419_420_421_422_423_424_425_426_427_428_429_430_431_432_433_434_435_436_437_438_439_440_441_442_443_444_445_446_447_448_449_450_451_452_453_454_455_456_457_458_459_460_461_462_463_464_465_466_467_468_469_470_471_472_473_474_475_476_477_478_479_480_481_482_483_484_485_486_487_488_489_490_491_492_493_494_495_496_497_498_499_500_501_502_503_504_505_506_507_508_509_GC START GC done.
510_511_512_513_514_515_516_517_518_519_520_521_522_523_524_525_526_527_528_529_530_531_532_533_534_535_536_537_538_539_540_541_542_543_544_545_546_547_548_549_550_551_552_553_554_555_556_557_558_559_560_561_562_563_564_565_566_567_568_569_570_571_572_573_574_575_576_577_578_579_580_581_582_583_584_585_586_587_588_589_590_591_592_593_594_595_596_597_598_599_600_601_602_603_604_605_606_607_608_609_610_611_612_613_614_615_616_617_618_619_620_621_622_623_624_625_626_627_628_629_630_631_632_633_634_635_636_637_638_639_640_641_642_643_644_645_646_647_648_649_650_651_652_653_654_655_656_657_658_659_660_661_662_663_664_665_666_667_668_669_670_671_672_673_674_675_676_677_678_679_GC START GC done.
680_681_682_683_684_685_686_687_688_689_690_691_692_693_694_695_696_697_698_699_700_701_702_703_704_705_706_707_708_709_710_711_712_713_714_715_716_717_718_719_720_721_722_723_724_725_726_727_728_729_730_731_732_733_734_735_736_737_738_739_740_741_742_743_744_745_746_747_748_749_750_751_752_753_754_755_756_757_758_759_760_761_762_763_764_765_766_767_768_769_770_771_772_773_774_775_776_777_778_779_780_781_782_783_784_785_786_787_788_789_790_791_792_793_794_795_796_797_798_799_800_801_802_803_804_805_806_807_808_809_810_811_812_813_814_815_816_817_818_819_820_821_822_823_824_825_826_827_828_829_830_831_832_833_834_835_836_837_838_839_840_841_842_843_844_845_846_847_848_849_GC START GC done.
850_851_852_853_854_855_856_857_858_859_860_861_862_863_864_865_866_867_868_869_870_871_872_873_874_875_876_877_878_879_880_881_882_883_884_885_886_887_888_889_890_891_892_893_894_895_896_897_898_899_900_901_902_903_904_905_906_907_908_909_910_911_912_913_914_915_916_917_918_919_920_921_922_923_924_925_926_927_928_929_930_931_932_933_934_935_936_937_938_939_940_941_942_943_944_945_946_947_948_949_950_951_952_953_954_955_956_957_958_959_960_961_962_963_964_965_966_967_968_969_970_971_972_973_974_975_976_977_978_979_980_981_982_983_984_985_986_987_988_989_990_991_992_993_994_995_996_997_998_999_1000_()
T
0]
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 06, 2014, 11:02:44 AM
Fine! Just make it print GC start in lowercase for consistency with GC done.

And with this version of rectest.lisp:

Code: [Select]
(define rectest (lambda (x)
(cond ((<= x (* 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000)) (rectest (+ x 1))))
))

(rectest 1)

you can shoot your eternal enemy Pritchard of FreeBASIC dead making his dream come true as your BASIC LISP counts recursively to 1E+30 + 1 autocleaning its memory in the process.

:D
Title: Re: Lisp in Basic
Post by: JRS on August 06, 2014, 11:21:23 AM
I don't have time for idiots anymore. Pritchard of FreeBASIC is in his own world.
Title: Re: Lisp in Basic
Post by: JRS on August 06, 2014, 11:38:18 AM
I'm not sure if this is working as you expected but it prints about 30 or so GC messages and waits. If I press the return key, it does it again. No way to get out other than a CTRL C.

@MIKE - Can you explain what this script is doing?

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 06, 2014, 12:03:37 PM
It defines a recursive function that checks its argument (x) for being less than or equal to

Code: [Select]
1000*1000*1000*1000*1000*1000*1000*1000*1000*1000
which is actually 10 to the 29th power. If its argument is less than or equal to this value, it calls its own self (i.e. recursively) with an argument of (x+1). The newly called instance checks its argument which is already (x+1) for being LEQ than 10E+29. If it's still LEQ, it calls its own self again with ((x+1)+1) and so forth, until ((x+1)...+n) is 10E+29 + 1 whereupon it exits.

This is essentially the same as

Code: [Select]
rectest 1

sub rectest (x)
  if x <= 1000*1000*1000*1000*1000*1000*1000*1000*1000*1000 then
    rectest x+1
  end if
end sub

in BASIC.

My FBSL LISP is running this code for 28 minutes already printing a column of GC START GC DONE's on and on. But the FBSL process memory is increasing slowly but steadily, yes. So there may still be a memleak somewhere. Perhaps SB is just a little more susceptible to it. I'll look into it later on.

Now, your assumption about IF PVALUE<>NUMBER OR QTYPE<>NUMBER THEN wasn't correct. This IF block must be commented out in both subprocedures. Also the comparison sign in DoBgr was wrong initially so the bug migrated to its DoLss derivative. So please change your existing subprocedures to the following to make < and > comparisons work properly:

Code: [Select]
:DoBgr
CTYPE=QTYPE
CVALUE=QVALUE
PTYPE=CTYPE
PVALUE=CVALUE
BSD=BSD+1
GOSUB Cdr
BSD=BSD+1
GOSUB RregtoPreg
BSD=BSD+1
GOSUB Car
BSD=BSD+1
GOSUB RregtoQreg
PTYPE=CTYPE
PVALUE=CVALUE
BSD=BSD+1
GOSUB Car
BSD=BSD+1
GOSUB RregtoPreg
IF PTYPE<>NUMBER OR QTYPE<>NUMBER THEN
PRINT "ERROR: IN >\n"
GOTO HandleError
END IF
'IF PVALUE<>NUMBER OR QTYPE<>NUMBER THEN
' PRINT "ERROR: IN >\n"
' GOTO HandleError
'END IF
IF PVALUE<QVALUE THEN
RTYPE=BOOLEANT
RVALUE=TRUE
BSD=BSD-1
RETURN
END IF
RTYPE=NULL
RVALUE=FALSE
BSD=BSD-1
RETURN

:DoLss
CTYPE=QTYPE
CVALUE=QVALUE
PTYPE=CTYPE
PVALUE=CVALUE
BSD=BSD+1
GOSUB Cdr
BSD=BSD+1
GOSUB RregtoPreg
BSD=BSD+1
GOSUB Car
BSD=BSD+1
GOSUB RregtoQreg
PTYPE=CTYPE
PVALUE=CVALUE
BSD=BSD+1
GOSUB Car
BSD=BSD+1
GOSUB RregtoPreg
IF PTYPE<>NUMBER OR QTYPE<>NUMBER THEN
PRINT "ERROR: IN <\n"
GOTO HandleError
END IF
'IF PVALUE<>NUMBER OR QTYPE<>NUMBER THEN
' PRINT "ERROR: IN <\n"
' GOTO HandleError
'END IF
IF PVALUE>QVALUE THEN
RTYPE=BOOLEANT
RVALUE=TRUE
BSD=BSD-1
RETURN
END IF
RTYPE=NULL
RVALUE=FALSE
BSD=BSD-1
RETURN
Title: Re: Lisp in Basic
Post by: JRS on August 06, 2014, 12:15:30 PM
Thanks Mike!

I'll make the corrections to the SBLisp source and get it posted on the repository.

What I might be seeing is the limit I set in the basic.conf file.

Code: [Select]
maxlevel 29666

I might set it to zero (no checks) and see if it blows up. (seg fault)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 06, 2014, 12:23:58 PM
Hehe actually I don't like the "666" - I'm a believer. And my Windows scriba.exe is working without a config file. :)
Title: Re: Lisp in Basic
Post by: JRS on August 06, 2014, 12:33:03 PM
You are correct. scriba doesn't require a basic.conf file to run. SB has default internal settings if a basic.conf can't be found or doesn't exist. The main reason I use a basic.conf is for the IMPORT/INCLUDE statement (ext. modules) to find the SB include and modules directory.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 06, 2014, 12:47:19 PM
Understood.

Now an update on scriba.exe+rectest.lisp. No memory leak at all - it prints the GC START GC DONE column smoothly on and on without interruptions. The memory pool of approx. 4.5MB stays as solid as a rock. :)
Title: Re: Lisp in Basic
Post by: JRS on August 06, 2014, 12:57:09 PM
It doesn't seem to have any memory leaks on the Linux version of SBLisp. Memory and the 100% CPU on one core remained consistent for over 15 minutes. I set maxlevel 0 to solve my premature exit issue.

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 06, 2014, 01:12:52 PM
This is very good - SB is consistent and LISP garbage collection is faultless.

Unfortunately this signals some slight internal memory leak specific to FBSL. :(

[UPD] But I know where it comes from. This entire program runs exclusively at the global level. But FBSL's internal GC can be triggered only at the points when FBSL exits from a lower level sub-script (scope), e.g. a user Namespace, Sub, Function, Property, Method, Overloaded Operator of a class instance, DynAsm or DynC block. It worked for years and I guess I'm not going to change it for the sake of a lone lisp.fbs script. It seems more reasonable to change the script's garbage collector into a genuine Sub instead. This way its automatic execution by the LISP interpreter will trigger concurrent garbage collection on the FBSL server side.

So I may sleep peacefully. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 07, 2014, 01:12:41 AM
John,

I wasn't correct about not being able to move the cursor to a new line while printing. The intrinsic newline procedure will do just that.

Consider the following sequence of procedures in a lambda (that's LISP lingo for "user-defined function"):

Code: [Select]
(print 'A) (newline) (print 'B) (newline)
It will print A and B on separate lines as shown in the picture. The trailing T is the result - return code - of overall evaluation (LISP lingo for "execution").

However the issue with printable spaces remains open.

.
Title: Re: Lisp in Basic
Post by: JRS on August 07, 2014, 01:21:26 AM
Good news!

Sure glad you're steering this boat.  8)

I started adding issues to the Bitbucket issue tracker if you can do the same with what you find.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 07, 2014, 01:28:45 AM
Sure glad you're steering this boat.

I'm intrigued by Charles' variadic average lambda challenge. Standard Scheme offers several options to denote a list of arbitrary length but I haven't yet figured out how to mimic it in SB/FBSL LISP.
Title: Re: Lisp in Basic
Post by: JRS on August 07, 2014, 01:47:57 AM
I'm still trying to figure out why (load (quote FF.SCM)) doesn't work in MIT/GNU Scheme.

Signing out. Zzzzzz
Title: Re: Lisp in Basic
Post by: RobbeK on August 07, 2014, 02:57:22 AM
Hi   John , Mike ..


I think in Racket Scheme and Bigloo the syntax is    (load "something.scm")    ?????

If this Scheme has "apply"  :

on a list :

(define (average L)
 (let ((x (length L)))
   (if (= 0 x)
     0
     (/ (apply + L) x ))))

(intercepts the empty list , avoiding a division by zero ).

best Rob

oops : somewhat incorrect to use 0 as a result  -- there is no result :

(define (average L)
 (let ((x (length L)))
   (if (= 0 x)
     (print "the list is empty , there can be no result")
     (/ (apply + L) x ))))

(or something alike : you can give back "nil" (the Lisp symbol for "the nothing" and false ) too )...

you can even map a condition first over the list examining if it are numbers

something as   if ( apply + on map::if the element is a number -> 0 else 1 ) =0 then the list is composed of numbers exclusively  ... etc etc ...
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 07, 2014, 04:34:05 AM
@John:

I suggested a tip (http://www.oxygenbasic.org/forum/index.php?topic=1147.msg10232#msg10232) on a working alternative to define literals in an expression. Please try (load 'FF.SCM) for a change and see what happens. But the both alternatives should work in standard Scheme equally well.


@Rob:

Hi,

(define (something something_else)) is not proper syntax for this LISP. Proper expressions would be (define something something_else), (define something (expression)), and (define something (lambda (optional_arg) ... )). But I'll try to blend your suggestions to this LISP's syntax. In the meantime, please see below.


@Charles:

Hi,

This is the best I could do so far. It is absolutely ugly but it works and it is variadic. I will also try to abridge Rob's suggestions though he simply doesn't realise how far the intrinsic flexibility of standard Scheme's syntax is from the Spartan minimality of SB/FBSL LISP.

So here's the Average.lisp script. It's runnable in FBSL LISP and both reincarnations of SBLisp:

Code: [Select]
(define accum 0)

(define average
  (lambda (input)
    (for-each (lambda (x) (set! accum (+ accum x))) input)
      (print (set! accum (/ accum (length input)))) (newline)
  )
)

(define args (list 1 2 3 4 5))

(average args)

and below is a snapshot with its results. Comments are given directly in the picture because SB/FBSL LISP doesn't support embedded comments yet.

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 07, 2014, 05:11:39 AM
[UPD]

Trial and error shows that the above script can be successfully reduced to the following, which eliminates effectively the need for an ARGS list:

Code: [Select]
(define accum 0)

(define average
  (lambda (input)
    (for-each (lambda (x) (set! accum (+ accum x))) input)
      (print (set! accum (/ accum (length input)))) (newline)
  )
)

(average (list 0 1 2 3 4 5 6 7 8 9))
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 07, 2014, 05:30:58 AM
[UPD]

Charles,

And the following will be my final solution with both ACCUM and ARGS symbols eliminated and substituted for with a local var and an explicit vararg list, respectively:

Code: [Select]
(define average
  (lambda (input)
    (let ((accum 0))
      (for-each (lambda (x) (set! accum (+ accum x))) input)
      (print (/ accum (length input))) (newline)
    )
  )
)

(average (list 0 1 2 3 4 5 6 7 8 9))

Ta-daaa....!

[EDIT] Fixed with a shorter print statement thanks to RobbeK.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 07, 2014, 06:00:37 AM
Thanks Mike,

It will take me a while to unravel that construction, though. I have a mental block in understanding lambda. I am distracted by thoughts of young sheep whenever I see it.

(http://www.photosbymcdonald.com/wp-content/uploads/2014/03/lamb.jpg)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 07, 2014, 06:26:05 AM
The Lamb (https://www.youtube.com/watch?v=TKS9np3GoWc). Starts at 1:15. Used to be one of my favorites.

I once had a college mate, a spitting image of Phil Collins of Genesis. Bold and scary as hell but terrifically popular with roadies and chicks in general. Now lives somewhere in Canada. Lost track of him somehow a few years back though.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 07, 2014, 06:39:22 AM
A lambda is actually a LISP declaration for a C/BASIC/etc user-defined function. Thus

Code: [Select]
(define foo
(lambda (bar)
...
)
)

stands for the following pseudo:

Code: [Select]
declare function foo (bar)
...
end function

Lambdas can also be anonymous similar to C closures, in which case they lack the "define" component and the corresponding name/label (as "foo" above):

Code: [Select]
(lambda (bar) ... )
The bar argument/multiple arguments is/are optional in both cases however its/their enclosing parentheses are mandatory at all times in SB/FBSL LISP.

My average solution features the both lambda flavors - a named outer
Code: [Select]
(define average
  (lambda (input)
  ...
  )
)

and an anonymous inner

Code: [Select]
(lambda (x) ... )
that's applied successively to each element in the input argument list of the outer average lambda. Iteration is performed by the for-each directive which has a specific "inverted" syntax: (for-each (lambda-to-apply) (list-of-elements-to-apply-lambda-to)).
Title: Re: Lisp in Basic
Post by: RobbeK on August 07, 2014, 07:00:25 AM
Hi Mike,  ok   but has it "apply" or not ?   (all the Schemes I ever used, have it -- and probably it was there from the beginning .. Scheme is somewhat older than Common Lisp though )

in that case  it simplifies (without the "division by zero" check ) to

(/  (apply + L) (length L))  ...

"(print (set! accum (/ accum (length input))))"    -- (print (/ accum (length input)))  is shorter, not ?  accum is local , so it can't be recycled anyway , no need to assign it   just for printing   (?)

best Rob

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 07, 2014, 07:17:08 AM
Hi Rob,

apply is the first entry in the BASIC LISP dictionary of keywords. The manual can be found in the SB and FBSL LISP distros available for download at the respective sites, or you can also read and/or download (http://www.cs.rit.edu/~anh/LISPinBASICWebDoc.pdf) it directly from the author's.

So yes, the apply construct may be used in SB/FBSL LISP and a check to avoid division by zero would be also welcome. I don't insist my solution is the best, or the shortest, or the most fool-proof, or the only one conceivable. It certainly isn't. But it is my solution, and I simply haven't had the time to try anything else. I still need to RTFM so very often... :)

And yes again, your (print (/ accum (length input))) suggestion is accepted with gratitude. It's definitely shorter while my assignment here was a piece of unnecessary extra bloat. The script is now fixed accordingly. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 07, 2014, 07:51:53 AM
!!! TA-DAAA AGAIN !!!

Here comes Rob's version of variadic average with one less lambda and one less local var but the exact same functionality:

Code: [Select]
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)

(average (list 0 1 2 3 4 5 6 7 8 9))

Welcome to the ranks, Rob! :D



.
Title: Re: Lisp in Basic
Post by: JRS on August 07, 2014, 08:53:01 AM
Quote from: Mike
or you can also read and/or download it directly from the author's.

Correction:  or you can also read and download a broken/incomplete copy directly from the author's site.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 07, 2014, 08:59:59 AM
I beg your pardon?

19/19 pages are an incomplete manual?
Title: Re: Lisp in Basic
Post by: JRS on August 07, 2014, 09:18:58 AM
Oh. I thought you were referring to the code.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 07, 2014, 09:32:52 AM
That's correct. The manual is precise, complete and instructive though somewhat laconic. OTOH the QB 4.5 source code is both uncompilable and buggy.

John and I have been able to fix it in our respective SB and FBSL scripts though to be compliant with the accompanying manual.
Title: Re: Lisp in Basic
Post by: RobbeK on August 07, 2014, 10:21:16 AM
Great Mike !

I think "apply" must be a macro ,   the primitive being :

(eval (cons an-operator a-list))

ran next in Bigloo Scheme and it works the same as in Common Lisp and Newlisp

(eval (cons +  (list 4 5 6)))  :::  identical with  (apply + (list 4 5 6)) 
in steps
(cons + (list 4 5 6))>  (+ 4 5 6)
(eval .. ) forces the evaluation , making it the anti-thesis of  '    (quote ...) which prohibits evaluation. 

now the next step in Lisp is mapping ..  (a picture shows more than 1000s words ->)

(map (lambda (x) (/ 1 x)) (list 1 2 3))  ->  ( 1  1/2 1/3 )

with apply and map, you have two of the most powerful tools of Lisp  ;)

best Rob !!



Title: Re: Lisp in Basic
Post by: JRS on August 07, 2014, 10:24:33 AM
I like the new load method Mike suggested.

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](load 'AVE.SCM)
AVE.SCM  1
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE

(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
T
0]
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 07, 2014, 10:39:05 AM
@Rob:

Thanks a lot for the heads-up! I'll try the cons trick later on tonight and will publish my results here.


@John:

The ' trick is implicit in the BASIC LISP code that's why I didn't notice it immediately. But it's commonplace in LISP and can substitute (quote something) at all times. In fact, it is a very handy shorthand.
Title: Re: Lisp in Basic
Post by: JRS on August 07, 2014, 03:56:44 PM
I was able to solve the SBLisp file name having to be upper case issue.

DoLoad:
Code: [Select]
  lispfilename = symbols[pvalue]
  OPTION COMPARE sbCaseInsensitive
  fnpos = INSTR(ibuf, lispfilename)
  IF fnpos THEN lispfilename = MID(ibuf, fnpos, LEN(lispfilename))
  OPTION COMPARE sbCaseSensitive

Testing
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](load 'Ave.scm)
Ave.scm  1
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE

(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
T
0]
Title: Re: Lisp in Basic
Post by: JRS on August 07, 2014, 05:47:48 PM
I was able to fix the problem with getting a ERROR: Read. if the script had extra blank lines at the end. What I did to fix this is if the position pointer exceed the input buffer length, I told SBLisp to go read another line and force the EOF() to kick in. The Ave.scm file had two extra blank lines at the end of the script.

GetNextToken:
Code: [Select]
  IF ipos > LEN(ibuf) THEN
'   PRINT "ERROR: Read.\n"
'   GOTO HandleError
    GOTO GetLine
  END IF

Testing
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](load 'Ave.scm)
Ave.scm  1
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE

(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T



T
0](quit)
Bye!
jrs@laptop:~/sb/sb22/sblisp$

Title: Re: Lisp in Basic
Post by: JRS on August 07, 2014, 06:30:47 PM
There still seems to be a problem with the blank lines at the end. If I have 2 extra blank lines, it works. (don't like the 2 for 1 PRINT though) If I use only one blank line, I get this error. ERROR: Problem in file Ave.scm  :o

Update

I got it to work with only one blank like and displaying as I would expect. The problem is I don't see the second T symbol which I still don't understand it's purpose. (true response to what?)

Code: [Select]
CheckDot:
  ipos+=1
  IF ipos > LEN(ibuf) THEN
'   PRINT "ERROR: Read.\n"
'   GOTO HandleError
    GOTO GetLine
  END IF

...

HandleError:
  IF lispfilenum <> 0 THEN
'   PRINT "ERROR: Problem in file ", lispfilename, "\n"

Update Mike said he will resolve this globally for both SB & FBSL.
Title: Re: Lisp in Basic
Post by: JRS on August 07, 2014, 09:35:35 PM
I've added an experimental startup command line script option. It allowed me to time the script execution which I couldn't do before. (SB only has 1 sec. resolution by default) I'm not pushing this to Bitbucket until Mike has a look. A (quit) is required in your command line script to exit SBLisp after completion otherwise it drops to a #] prompt.

Code: [Select]
' The original author of this code is Arthur Nunes-Harwitt

cmdln = COMMAND()
IF LEN(cmdln) THEN
  cmdflg = TRUE
ELSE
  cmdflg = FALSE
END IF

...

GetLine:
  IF cmdflg THEN
    ibuf = "(load '" & cmdln & ")"
    ipos = 1
    cmdflg = FALSE
    bsd -=1
    RETURN
  END IF

Testing
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ time scriba lisp.sb Ave.scm
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE

(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
(quit)
Bye!

real 0m0.240s
user 0m0.232s
sys 0m0.008s
jrs@laptop:~/sb/sb22/sblisp$

Something a bit more demanding.

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ time scriba lisp.sb rectest.scm
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
(define rectest (lambda (x)
(cond ((<= x (* 1000)) (print x) (print '_) (rectest (+ x 1))))
))
RECTEST

(rectest 1)
1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39_40_41_42_43_44_45_46_47_48_49_50_51_52_53_54_55_56_57_58_59_60_61_62_63_64_65_66_67_68_69_70_71_72_73_74_75_76_77_78_79_80_81_82_83_84_85_86_87_88_89_90_91_92_93_94_95_96_97_98_99_100_101_102_103_104_105_106_107_108_109_110_111_112_113_114_115_116_117_118_119_120_121_122_123_124_125_126_127_128_129_130_131_132_133_134_135_136_137_138_139_140_141_142_143_144_145_146_147_148_149_150_151_152_153_154_155_156_157_158_159_160_161_162_163_164_165_166_167_168_169_GC start GC done.
170_171_172_173_174_175_176_177_178_179_180_181_182_183_184_185_186_187_188_189_190_191_192_193_194_195_196_197_198_199_200_201_202_203_204_205_206_207_208_209_210_211_212_213_214_215_216_217_218_219_220_221_222_223_224_225_226_227_228_229_230_231_232_233_234_235_236_237_238_239_240_241_242_243_244_245_246_247_248_249_250_251_252_253_254_255_256_257_258_259_260_261_262_263_264_265_266_267_268_269_270_271_272_273_274_275_276_277_278_279_280_281_282_283_284_285_286_287_288_289_290_291_292_293_294_295_296_297_298_299_300_301_302_303_304_305_306_307_308_309_310_311_312_313_314_315_316_317_318_319_320_321_322_323_324_325_326_327_328_329_330_331_332_333_334_335_336_337_338_339_GC start GC done.
340_341_342_343_344_345_346_347_348_349_350_351_352_353_354_355_356_357_358_359_360_361_362_363_364_365_366_367_368_369_370_371_372_373_374_375_376_377_378_379_380_381_382_383_384_385_386_387_388_389_390_391_392_393_394_395_396_397_398_399_400_401_402_403_404_405_406_407_408_409_410_411_412_413_414_415_416_417_418_419_420_421_422_423_424_425_426_427_428_429_430_431_432_433_434_435_436_437_438_439_440_441_442_443_444_445_446_447_448_449_450_451_452_453_454_455_456_457_458_459_460_461_462_463_464_465_466_467_468_469_470_471_472_473_474_475_476_477_478_479_480_481_482_483_484_485_486_487_488_489_490_491_492_493_494_495_496_497_498_499_500_501_502_503_504_505_506_507_508_509_GC start GC done.
510_511_512_513_514_515_516_517_518_519_520_521_522_523_524_525_526_527_528_529_530_531_532_533_534_535_536_537_538_539_540_541_542_543_544_545_546_547_548_549_550_551_552_553_554_555_556_557_558_559_560_561_562_563_564_565_566_567_568_569_570_571_572_573_574_575_576_577_578_579_580_581_582_583_584_585_586_587_588_589_590_591_592_593_594_595_596_597_598_599_600_601_602_603_604_605_606_607_608_609_610_611_612_613_614_615_616_617_618_619_620_621_622_623_624_625_626_627_628_629_630_631_632_633_634_635_636_637_638_639_640_641_642_643_644_645_646_647_648_649_650_651_652_653_654_655_656_657_658_659_660_661_662_663_664_665_666_667_668_669_670_671_672_673_674_675_676_677_678_679_GC start GC done.
680_681_682_683_684_685_686_687_688_689_690_691_692_693_694_695_696_697_698_699_700_701_702_703_704_705_706_707_708_709_710_711_712_713_714_715_716_717_718_719_720_721_722_723_724_725_726_727_728_729_730_731_732_733_734_735_736_737_738_739_740_741_742_743_744_745_746_747_748_749_750_751_752_753_754_755_756_757_758_759_760_761_762_763_764_765_766_767_768_769_770_771_772_773_774_775_776_777_778_779_780_781_782_783_784_785_786_787_788_789_790_791_792_793_794_795_796_797_798_799_800_801_802_803_804_805_806_807_808_809_810_811_812_813_814_815_816_817_818_819_820_821_822_823_824_825_826_827_828_829_830_831_832_833_834_835_836_837_838_839_840_841_842_843_844_845_846_847_848_849_GC start GC done.
850_851_852_853_854_855_856_857_858_859_860_861_862_863_864_865_866_867_868_869_870_871_872_873_874_875_876_877_878_879_880_881_882_883_884_885_886_887_888_889_890_891_892_893_894_895_896_897_898_899_900_901_902_903_904_905_906_907_908_909_910_911_912_913_914_915_916_917_918_919_920_921_922_923_924_925_926_927_928_929_930_931_932_933_934_935_936_937_938_939_940_941_942_943_944_945_946_947_948_949_950_951_952_953_954_955_956_957_958_959_960_961_962_963_964_965_966_967_968_969_970_971_972_973_974_975_976_977_978_979_980_981_982_983_984_985_986_987_988_989_990_991_992_993_994_995_996_997_998_999_1000_()
(quit)
Bye!

real 0m1.441s
user 0m1.428s
sys 0m0.008s
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: JRS on August 07, 2014, 10:45:28 PM
I was trying some of the examples in the Lisp in BASIC docs and ran into a discrepancy. (last expression)

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](let ((x 5)) (+ x 1))
6
0](+ '5 '6)
11
0](/ 12 2 3)
0.666667
0]

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ mit-scheme
MIT/GNU Scheme running under GNU/Linux
Type `^C' (control-C) followed by `H' to obtain information about interrupts.

Copyright (C) 2014 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Image saved on Saturday May 17, 2014 at 2:39:25 AM
  Release 9.2 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || Edwin 3.116

1 ]=> (/ 12 2 3)

;Value: 2

1 ]=>
Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 07:32:52 AM
Why MIT switched from Scheme to Python

Q. Costanza asked Sussman why MIT had switched away from Scheme for their introductory programming course?

A. Well, said Sussman, it probably just had a library already implemented for the robotics interface, that was all.

Once again, right place, right time and a current need is all that matters to define the future.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 09:56:29 AM
A quick overview of currently known issues:

1. Yes, more than 1 extra blank line at the end of the file make the LISP parser choke in QB45, FBSL and SB alike. This signifies an initial design fault, supposedly, the inability to correctly intercept an EOF event. The lookahead depth in the parsing loop is 1 char only. There's no looping in an empty line; no looping -> no lookahead -> no EOF interception.

2. (/ A B C) and (- A B C) yield trash in QB45, FBSL and SB alike. (+ A B C) and (* A B C) are correct. Another initial design bug.

3. BASIC LISP's T stands for TRUE, () stands for FALSE. Every math or logical evaluation sends its result to the console transparently without an explicit (print something). The explicit print can additionally enforce LISP to output data which isn't part of the evaluation process.

LISP's "evaluation" is what we usually call "execution" in normal human speech. Implicit evaluation is applied to everything that is enclosed in a pair of matching parentheses. Apart from implicit evaluation, LISP also has an explicit (eval [']something) command that additionally returns whatever an executable something has already returned, or turns 'something into an executable and returns only its own evaluation of this otherwise non-executable literal.

From the LISP perspective, execution of a program file as a whole is a command to (eval 'string_literal_with_entire_file_contents). It adds a trailing T (TRUE) to the console output to denote successful completion of the eval command. Failure to evaluate 'something would result in () (FALSE) if only the evaluation process didn't trigger some other error that LISP is responsive to.

In other words, T and () serve as program success/failure return codes in LISP file evaluation.

I find this behavior logically reasonable and I wouldn't fight to suppress it.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 12:15:09 PM
Issue 1 fixed!

John,

Will you please undo your repo sources of SBLisp so that I could use them for my future submissions here? Thank you.

Until then please just change the following notation to your SBLisp's equivalent naming convention:

Code: [Select]
GetLine:
IF LispFileNum=0 THEN
PRINT LTRIM(FORMAT("%~##~",OPAREN)), "]"
LINE INPUT I
I = CHOMP(I)
IF ASC(I) = undef THEN GOTO GetLine
IPOS = 1
ELSE
IF NOT EOF(LispFileNum) THEN
LINE INPUT# LispFileNum, I
I = CHOMP(I)
IF ASC(I) = undef THEN GOTO GetLine
PRINT I, "\n"
IPOS = 1
ELSE
GOTO LispCloseFile
END IF
END IF
BSD=BSD-1
RETURN

This will effectively fix 2 issues at once:

1a. Extra trailing empty lines in a LISP file; and

1b. Pressing Enter repeatedly with no input in the interactive mode which would currently render LISP inoperative and unresponsive to further commands once it would hit the first READ ERROR.
Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 12:35:59 PM
Quote
Will you please undo your repo sources of SBLisp so that I could use them for my future submissions here?

I don't understand what you mean by release the sources from Bitbucket. Do you undo my change to try and fix the extra lines issue?

Thanks for knocking this one off the list!

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 12:50:08 PM
I didn't mean to "release". I used your own figure of speech as shown in the attached picture. Your previous fix for the extra lines can be reverted too because mine seems more compact and effectively addresses two issues at once.

[EDIT] !!! AHA !!! I got it! You meant "NOT" undone! I misunderstood it for "Not undone". Sorry, my bad! :D

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 12:55:45 PM
OK then wait a minute while I'm downloading the sources. I'll update my code above and then you can copy-paste it directly. Just wait a little.

[UPD] Please hold on. Your repo version doesn't work as expected. My original SBLisp does while yours certainly doesn't. I need more time for merge compare them and I'll be posting the sources in a separate message as soon as I get them fixed.
Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 01:39:12 PM
Sounds good Mike. BTW, you are able to download any of the uploads I made to Bitbucket. Just look at the history and pick the version you want. Bitbucker has a great compare feature.

Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 02:47:10 PM
Your fixes have been incorporated in the latest Bitbucket source. SBLisp also has command line script load support and mixed case filenames. Here are my quick tests. The first run had only one blank line at the end. The second had two blank lines and the third run shows running a script from the command line. (Mixed case filename)

Thanks again Mike. Great job!

Code: [Select]
jrs@laptop:~$ cd sb/sb22/sblisp
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
0](load 'Ave.scm)
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE
(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
0]   
0](quit)
Bye!
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
0](load 'Ave.scm)
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE
(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
0](quit)
Bye!
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb Ave.scm
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE
(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
(quit)
Bye!
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 03:49:58 PM
Why thanks John,

But I think you were just a little too fast to update it there.

Here's the latest version with all your extra blank line fixes nullified, filename DEBUG stuff removed (I presume you already have this running), and my fixes above added.

There's one more thing fixed. Once loaded and run from the file, the procedures should be runnable in an interactive mode too. FBSL does it without problems while SB runs a preloaded procedure for the first time but aborts on a second try with a bad file number error.

Try to (load 'Ave.scm) and run it then type (average (list 0 1 2 3 4 5 6 7 8 9)) (or (average '(0 1 2 3 4 5 6 7 8 9)) which is the same but shorter) and it will execute your command. But if you enter it again, it will execute it but will then break on SB's internal error. I can't trace the offending script line number (my scriba.exe won't show it).

So I have simply re-enabled SB's ON ERROR GOTO and HandleInternalError with a RESUME NEXT statement. That's a palliation because this effectively disables all own SB errors. My setup has neither a config file nor an include dir with errors.bas so I can't differentiate the error codes with error() and thus intercept and sink error &h14 only.

You can add your effort to our common cause by adding the errors.bas include to your setup and changing the existing error handler to

Code: [Select]
HandleInternalError:
  IF ERROR() = &H14 THEN
    ' Re-enable error trapping
    ON ERROR GOTO HandleInternalError
    ' Resume at next line
    RESUME NEXT
  END IF
  ' Resume at same line
  RESUME

just to test if it kills the bug as efficiently. Such a trap would suppress this particular bug only but would not ignore any other errors intrinsic to SB.

This error trap is impossible with my scriba.exe without the errors.bas include.

.
Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 04:01:18 PM
I removed my blank line attempt before adding your fixes to the source. Please use the one on BitBucket as the MASTER to modify and use my formating rules.

Keywords - UPPER CASE
Labels / Functions / Subs - Mixed Case
Variables (ALL) - lower case

I think we  are good with the version I have posted.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 04:17:46 PM
John,

Where do you see but one single deviation from these formatting rules in my submission above?

Secondly, I will not work in such a pseudo-parallel mode on the SB sources. Please wait till I upload and announce that I'm trough whenever I take the SBList file down for work.

Didn't I ask you to hold on till I finish? I've done four major fixes instead of one planned.

I will not come back to the SBLisp sources until you assure me that the file I uploaded with the fix that I asked you to add is tested and uploaded to the repo as its final.

>:(
Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 04:30:30 PM
Mike,

I think I added all the fixes you ask me to make. Can you look at the current Bitbucket source and tell me what is missing? Here is my test of loading a script from the command line and following it up with another load. I didn't get a file in use SB error.

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb Ave.scm
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE
(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
0](load 'rectest.scm)
(define rectest (lambda (x)
(cond ((<= x (* 1000)) (print x) (print '_) (rectest (+ x 1))))
))
RECTEST
(rectest 1)
1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_33_34_35_36_37_38_39_40_41_42_43_44_45_46_47_48_49_50_51_52_53_54_55_56_57_58_59_60_61_62_63_64_65_66_67_68_69_70_71_72_73_74_75_76_77_78_79_80_81_82_83_84_85_86_87_88_89_90_91_92_93_94_95_96_97_98_99_100_101_102_103_104_105_106_107_108_109_110_111_112_113_114_115_116_117_118_119_120_121_122_123_124_125_126_127_128_129_130_131_132_133_134_135_136_137_138_139_140_141_142_143_144_145_146_147_148_149_150_151_152_153_154_155_156_157_158_159_160_161_162_GC start GC done.
163_164_165_166_167_168_169_170_171_172_173_174_175_176_177_178_179_180_181_182_183_184_185_186_187_188_189_190_191_192_193_194_195_196_197_198_199_200_201_202_203_204_205_206_207_208_209_210_211_212_213_214_215_216_217_218_219_220_221_222_223_224_225_226_227_228_229_230_231_232_233_234_235_236_237_238_239_240_241_242_243_244_245_246_247_248_249_250_251_252_253_254_255_256_257_258_259_260_261_262_263_264_265_266_267_268_269_270_271_272_273_274_275_276_277_278_279_280_281_282_283_284_285_286_287_288_289_290_291_292_293_294_295_296_297_298_299_300_301_302_303_304_305_306_307_308_309_310_311_312_313_314_315_316_317_318_319_320_321_322_323_324_325_326_327_328_329_330_GC start GC done.
331_332_333_334_335_336_337_338_339_340_341_342_343_344_345_346_347_348_349_350_351_352_353_354_355_356_357_358_359_360_361_362_363_364_365_366_367_368_369_370_371_372_373_374_375_376_377_378_379_380_381_382_383_384_385_386_387_388_389_390_391_392_393_394_395_396_397_398_399_400_401_402_403_404_405_406_407_408_409_410_411_412_413_414_415_416_417_418_419_420_421_422_423_424_425_426_427_428_429_430_431_432_433_434_435_436_437_438_439_440_441_442_443_444_445_446_447_448_449_450_451_452_453_454_455_456_457_458_459_460_461_462_463_464_465_466_467_468_469_470_471_472_473_474_475_476_477_478_479_480_481_482_483_484_485_486_487_488_489_490_491_492_493_494_495_496_497_498_499_GC start GC done.
500_501_502_503_504_505_506_507_508_509_510_511_512_513_514_515_516_517_518_519_520_521_522_523_524_525_526_527_528_529_530_531_532_533_534_535_536_537_538_539_540_541_542_543_544_545_546_547_548_549_550_551_552_553_554_555_556_557_558_559_560_561_562_563_564_565_566_567_568_569_570_571_572_573_574_575_576_577_578_579_580_581_582_583_584_585_586_587_588_589_590_591_592_593_594_595_596_597_598_599_600_601_602_603_604_605_606_607_608_609_610_611_612_613_614_615_616_617_618_619_620_621_622_623_624_625_626_627_628_629_630_631_632_633_634_635_636_637_638_639_640_641_642_643_644_645_646_647_648_649_650_651_652_653_654_655_656_657_658_659_660_661_662_663_664_665_666_667_GC start GC done.
668_669_670_671_672_673_674_675_676_677_678_679_680_681_682_683_684_685_686_687_688_689_690_691_692_693_694_695_696_697_698_699_700_701_702_703_704_705_706_707_708_709_710_711_712_713_714_715_716_717_718_719_720_721_722_723_724_725_726_727_728_729_730_731_732_733_734_735_736_737_738_739_740_741_742_743_744_745_746_747_748_749_750_751_752_753_754_755_756_757_758_759_760_761_762_763_764_765_766_767_768_769_770_771_772_773_774_775_776_777_778_779_780_781_782_783_784_785_786_787_788_789_790_791_792_793_794_795_796_797_798_799_800_801_802_803_804_805_806_807_808_809_810_811_812_813_814_815_816_817_818_819_820_821_822_823_824_825_826_827_828_829_830_831_832_833_834_835_836_GC start GC done.
837_838_839_840_841_842_843_844_845_846_847_848_849_850_851_852_853_854_855_856_857_858_859_860_861_862_863_864_865_866_867_868_869_870_871_872_873_874_875_876_877_878_879_880_881_882_883_884_885_886_887_888_889_890_891_892_893_894_895_896_897_898_899_900_901_902_903_904_905_906_907_908_909_910_911_912_913_914_915_916_917_918_919_920_921_922_923_924_925_926_927_928_929_930_931_932_933_934_935_936_937_938_939_940_941_942_943_944_945_946_947_948_949_950_951_952_953_954_955_956_957_958_959_960_961_962_963_964_965_966_967_968_969_970_971_972_973_974_975_976_977_978_979_980_981_982_983_984_985_986_987_988_989_990_991_992_993_994_995_996_997_998_999_1000_()
0]

Lets sync up and I will only post what you send me until we get through these series of bugs.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 04:47:13 PM
OK John.

Let's plan it this way:

1. I'm downloading a copy of the repo.
2. I'm compare-merging it with my latest submission if there's anything to merge at all.
3. I'm uploading my merger here.
4. You're overwriting my HandleInternalError: with your HandleInternalError: that I posted for you as a code snippet here (http://www.oxygenbasic.org/forum/index.php?topic=1147.msg10317#msg10317).
5. You're adding a line to include SB's standard errors.bas include to your script.
6. You're loading Ave.scm and running it.
7. Without exiting from LISP, you type in (average '(0 1 2 3 4 5 6 7 8 9)) at the LISP prompt and hit Enter, then repeat it at least 2 more times not quitting LISP to see that it doesn't throw an SB exception.
8. You're posting your findings as per Item 7 above here.
9. We're taking a decision on whether to upload your resultant lisp.sb to the repo as its final version.

Is that OK with you?

Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 04:50:06 PM
Works for me.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 04:51:26 PM
OK then ready, steady, go...
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 05:07:35 PM
Hehe John,

I appreciated and preserved your command line attraction intact. :)

Here comes the release candidate. Please proceed as per Item 4 of our plan.

.
Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 05:19:28 PM
Quote
8. You're posting your findings as per Item 7 above here.

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb Ave.scm
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE
(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
0](average '(0 1 2 3 4 5 6 7 8 9))
4.500000
T
0](average '(0 1 2 3 4 5 6 7 8 9))
4.500000
T
0](average '(0 1 2 3 4 5 6 7 8 9))
4.500000
T
0](average '(0 1 2 3 4 5 6 7 8 9))
4.500000
T
0]


.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 05:30:42 PM
Cool, thanks! It worked!

Thanks for the include too. Not sure if I can use it tho. My scriba.exe wasn't fully set up; it was just a manual copy of the executable. IIRC I can't write an ASCII config - it should be precompiled as a binary file by the installer, shouldn't it?

Now I think your RC may go to the repository. We've done quite a piece of work. The / and - bugs may wait till tomorrow. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 05:40:31 PM
Where are the flowers, champagne and heavenly music? I have become a Hero Member on this forum just like Aurel. And I guess by somewhat similar criteria.

8)
Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 05:45:53 PM
Quote
Not sure if I can use it tho. My scriba.exe wasn't fully set up;

error.bas is an include only and doesn't try to load any extension modules. Just put it in the same directory as lisp.sb and put quotes around the file name after IMPORT.

Quote
Where are the flowers, champagne and heavenly music? I have become a Hero Member on this forum ...

Hell, I would give you a hug if I could.  ;D

Does this mean I can post this to Bitbucket?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 05:57:34 PM
!!! COOL !!! The include file and the script work for me too!

The other SB errors aren't affected. Just try to (load 'a-non-existent-file) and you'll get an ordinary SB exception while this very bug with an improper file number is totally suppressed.

Yes John, I think this lisp.sb can now go to Bitbucket. We'll look into the / and - bugs tomorrow. Thanks for co-operation!
Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 06:33:31 PM
I regenerated a new error.bas from current Script BASIC v2.2 source if you want to replace what you have with this. (may be the same ?) I will include error.bas in the Bitbucket repository.


.
Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 07:12:05 PM
I added additional contributor / repo location info about SBLisp to the header of the code. I would like to display SBLisp version .## or something like that and remove the old QB version startup.

Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 07:46:18 PM
If this project holds your interest, we could use Charles's DLLC to multi-thread SBLisp and use it to load Dave IDE/Debugger as a COM control. The Script BASIC MT extension module could be used to share (lockable RW) variables between threads.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 07:59:19 PM
Thanks for the new error.bas. It is actually identical to the old one except for the version line.

I would like to display SBLisp version .## or something like that ...

You may place your own copyright blurb at the very top of the file and propagate the older credits further down the page. You may follow it with the code line to display the current SBLisp version as you say.

Quote
and remove the old QB version startup.

You may do it freely. But you may not remove the older blurb (credits to previous contributors) from the script altogether. This code is not in the public domain and it must preserve all the credits it has acquired throughout its lifetime. The older ones go down the page while the newer ones are being added at the top. This is what your GNU GPL law teaches you to do. ;)

Quote
If this project holds your interest...
At the current complexity of the source code and with a usable error.bas include, I can manage in a simple Notepad and an incremental debugger isn't really necessary for me (I think...)


G'night! :)
Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 08:04:56 PM
This is what is currently on Bitbucket.

Code: [Select]
' This work is licensed under the Creative Commons
' Attribution-NonCommercial-ShareAlike License. To view a copy of this
' license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or
' send a letter to Creative Commons, 171 Second St, Suite 300
' San Francisco, CA 94105, USA.

' The original author of this code is Arthur Nunes-Harwitt
' SBLisp version by John Spikowski and Mike Lobanovsky - Aug. 8th, 2014
' Bitbucket Repository: https://bitbucket.org/ScriptBasic/sblisp

I agree the above must remain intact but doesn't need to show at startup especially since  we are in essence creating a derivative.  I just don't see the need for it to be displayed every time at startup. If it was a compiled program that would be different.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 08:26:19 PM
Quote
I just don't see the need for it to be displayed every time at startup.
That's correct.

But the order of credits still isn't strictly canonical. You should move the two trailing commented lines to the very top of the page and leave a blank line beneath them so that all the old stuff goes right down the page. If this CCA license is GNU compatible (needs special investigation) then you can even add your own GPL prayer beneath the two topmost lines thus moving your predecessors yet further down. :)

(http://rlv.zcache.com/teamwork_kids_postcards-racd7f52cf81843c7b55e65724ab95bbc_vgbaq_8byvr_512.jpg)
Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 08:47:03 PM
I tried getting SBLisp to run multi-threaded and it worked. (sort of) Both threads were sharing the same console.  :-\ Charles designed this multi-threaded environment for IUP. Maybe he has an idea how we can used it with SBLisp.

I'm seriously looking at sbhttpd as a SBLisp multi-threaded server. I would need to pass simple CGI headers but everything else can be standard SB code and it doesn't care if it's not talking to a browser. I think I'm going play in this sandbox for awhile as it would work on both Windows and Linux. (DLLC is Windows only)

OR

Do a web browser version of SBLisp with sbhttpd. Libraries of functions could be readily available to use with your uploaded scripts.


Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 09:46:35 PM
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
SBLisp - Scheme BASIC Lisp

0]

Quote
' SBLisp version by John Spikowski and Mike Lobanovsky - Aug. 8th, 2014
' Bitbucket Repository: https://bitbucket.org/ScriptBasic/sblisp
'
' This work is licensed under the Creative Commons
' Attribution-NonCommercial-ShareAlike License. To view a copy of this
' license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or
' send a letter to Creative Commons, 171 Second St, Suite 300
' San Francisco, CA 94105, USA.
'
' The original author of this code is Arthur Nunes-Harwitt
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 10:50:36 PM
Hmmm not bad, not bad... :)

( the "-" bug has been fixed, the "/" one is on its last legs 8) )
Title: Re: Lisp in Basic
Post by: JRS on August 08, 2014, 10:59:58 PM
I think more people will contribute if its not a Script BASIC only project. SB just happens to be what it's being developed in. (traditional BASIC) There is very little SB specific code here.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 08, 2014, 11:15:32 PM
While you were preoccupied with that wishful thinking, the both bugs were killed with utmost brutality and died in terrible agony shrieking uselessly for mercy.

Exorcism over, I'm off to bed a little tired of my righteous works. 8)
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 06:56:44 AM
Good morning.

FYI - Site slowness was due to external access attempts to log into the MySQL server by hackers. External MySQL access has been disabled and we should no longer see slow downs here at OxygenBasic.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 09:36:28 AM
G'morning John,

Here comes the latest SBLisp with the - and / bugs fixed and a ; comment character added. 8)

Enjoy! :)

.
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 09:41:43 AM
Charles, move over, we have a contending wizard in the mist.   8)

Thanks Mike!

I'll do a quick scan for format (spaces between vars and operators, arg lists, ...) and push it to the SBLisp repository.

Should I spend some time testing or do you have that already covered?

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 09:50:01 AM
The fixes work perfectly in both SB and FBSL under Windows. Please have a try in Linux too before uploading to the repo.
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 10:02:48 AM
No T response anymore?

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
SBLisp - Scheme BASIC Lisp

0](/ 12 2 3)
2
0]; Works under Linux
0](quit)
Bye!
jrs@laptop:~/sb/sb22/sblisp$

SBLisp repository code updated.

Oh. I guess T is a loaded script response message?

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb Ave.scm
SBLisp - Scheme BASIC Lisp

(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE
(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
0]

Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 11:02:36 AM
What's next?

It would be nice to have a help feature in SBLisp.

Can we eliminate the limitations (MAX settings) on arrays so we can deal with larger / more complex scripts?

I would like to have a tutorial/instructions on adding new symbols to SBLisp.

What is the format you plan to use for external resources (SDL, SQLite, Scheme library sets (pkg), ...)

P.S. I would like to see the current FBSL version of SBLisp if you have time to post or point us to a link to download.

Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 02:19:00 PM
I'm going to take the lead on the web browser version of SBLisp. Hope to have something to show soon.

@Mike - Let me know when you think SBLisp is solid and I create a SBLisp.apk for Android.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 02:50:05 PM
What's next?
It seems reasonable to make BASIC LISP look more like standard Scheme. E.g. (print) isn't Scheme while (display) is. A list of missing functionality and keywords would be welcome.

Quote
It would be nice to have a help feature in SBLisp.
Not feasible. The 19-page PDF is the absolute minimum to allow a BASIC-er to write the simplest LISP lambda. Been there, done that.

Quote
Can we eliminate the limitations (MAX settings) on arrays so we can deal with larger / more complex scripts?
Something's telling me this problem is non-existent in SB with its dynamic-only arrays. Once the initial arrays are created and initialized, they may grow on and on automatically as their newer elements are referred to for the first time.

FBSL currently uses static Variant arrays that may grow with REDIM PRESERVE when necessary. Alternatively, slight changes may be added to the code in order to use dynamically growable Variant arrays exactly like those in SB.

Quote
I would like to have a tutorial/instructions on adding new symbols to SBLisp.
Let's have a list of missing keywords first (see above) -- that's what postage stamp collectors would call a manque-liste a-la francais -- and then try to implement the simplest ones that have very close correspondence to the existing ones, e.g. trigonometric functions. This will develop a "feeling" for the source code structure and teach us what is what in it and why. Then more complicated cases may be tackled as our experience grows.

Quote
What is the format you plan to use for external resources (SDL, SQLite, Scheme library sets (pkg), ...)
I don't have any particular plans for now. Frankly, I'm not interested in that language very much as it is. It's more about that sort of a drive that I'm feeling while cracking all these brainteasers in a piece of alien code.

Perhaps Charles can give you some ideas unless he's building his LispishLisp out of similar curiosity. :)

Quote
P.S. I would like to see the current FBSL version of SBLisp if you have time to post or point us to a link to download.
You can download raw source code and a precompiled executable (http://www.fbsl.net/phpbb2/viewtopic.php?f=26&t=3028#p10561) from the FBSL site.

Quote
Let me know when you think SBLisp is solid...
Time and tests will show. AS IS ==> no warranties given, no responsibility assumed. This isn't my own code after all. I would have never written it in this style in the first place, or I would've rewritten it a hundred times since the 90s.
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 03:12:07 PM
Quote
I don't have any particular plans for now.

Quote
It seems reasonable to make BASIC LISP look more like standard Scheme.

What that tells me is I should follow the path of MIT/GNU Scheme with external resource syntax but don't expect any guidance in this area from you. Correct?

Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 03:27:55 PM
Quote
You can download raw source code and a precompiled executable from the FBSL site.

That updated zip looks a bit dated and still has the (/  ...) error. Your last post says redownload the zip. The file dates say 8/9.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 03:38:04 PM
It seems to me every language has a basic set of keywords and associated functionality that has to be implemented in the language for it to outgrow its Toy attribute. Are you sure SBLisp is currently broad enough to deal with the problems that "the gold standard" is capable of dealing with without external modules/libraries? I am not.

I can follow, and take part in, your effort in that direction. And I will be doing this just for the fun of it. You can delete my name from the SBLisp blurb any time -- I won't question it or even notice it because publicity isn't why I'm doing this.

But I'm not sure if I should be involved in building SB modules/extensions/bundles/whatever to connect the newly-born SBLisp object to your future activities and visions of its projected spheres of applicability. SB has everything it needs for this purpose thanks to Peter who did his best to see to it a decade ago. I can hardly add anything to it. And I'm an FBSL, not SB, developer after all. :)

If you (or we) can ensure the base functionality of SBLisp and, at the same time, its seamless interoperability with external modules/libraries then I don't see why you shouldn't take Scheme as a model to follow. Even if you are not able to jump over their head in the end, you'll gain valuable experience and a lot of fun in the process. :)
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 03:46:31 PM
Okay. Let me know what you need me to do and I'll follow your lead. Getting SBLisp solid in it's current form seems like a good plan to me.

I'm still confused about what you said that SB expands it's arrays beyond the initialized state. Isn't there max array size variables being set to check for exceeding these predefined states?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 03:59:16 PM
Quote
That updated zip looks a bit dated and still has the (/  ...) error.
Ain't no slightest idea what you're talking about. See the picture of (/ ...) running in the exe and raw script modes. I have just downloaded the zip from the site.

Quote
Your last post says redownload the zip. The file dates say 8/9.
The second picture is what my file dates and times say in my Russian WinRAR. August the 9th has ended exactly 3 hours ago here. It's 3 o'clock in the morning Sunday August 10.


If you don't see the same on your PC/notebook, perhaps you should clear your download cache and retry.


P.S. And please also note: this is not an FBSL port of your SBLisp. I created this script directly from the QB45 original. It may contain a couple of lines from SBLisp that wandered into there as a stencil while I was developing the both of them but it certainly isn't a port of your own code. That's why it doesn't contain either your blurb or your file load command line. Actually it doesn't contain my name either. :)

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 04:26:20 PM
I'm still confused about what you said that SB expands it's arrays beyond the initialized state. Isn't there max array size variables being set to check for exceeding these predefined states?
Judging from what I read in Peter's docs, you might not need any initialization at all. If it is so, then SB's arrays behave exactly like FBSL's dynamic arrays: their elements are created totally on the fly at the moment they are referenced in the code for the first time if they haven't been referenced yet.

Just for the heck of it, try the following and see what happens in your Linux:

Code: [Select]
  maxheapsize=4000
  'FOR mem = 0 TO maxheapsize
  '  heaptype[mem,0] = 0
  '  heaptype[mem,1] = 0
  '  heapvalue[mem,0] = 0
  '  heapvalue[mem,1] = 0
  'NEXT mem

  maxsymboltablesize = 2000
  FOR mem = 0 TO maxsymboltablesize
    symbols[mem] = ""
  NEXT mem
  slotsfilled = 0

  maxstacksize = 2000
  'FOR mem = 0 TO maxstacksize
  '  stacktype[mem] = 0
  '  stackvalue[mem] = 0
  'NEXT mem

 ::)
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 04:31:04 PM
Works fine. That isn't my concern. Isn't a maxheapsize check done in the program and an out of memory error occurs if exceeded?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 04:48:46 PM
1. Have you tried it or not?

2. If that trick works then why not just change 4000 for maxheapsize to, say, 40,000,000 and maxstacksize, to 10,000,000 just for starters? And let the computer decide when it should really clear its stack? The test (Rec_Test.lisp or whatever it was called) should then hardly ever print GC start GC done. :)
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 04:53:37 PM
Yes I tried it. (REM out FOR/NEXT init)

That was my next question, what triggers auto GC.

Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 05:05:36 PM
Used your recommended settings for the max values and never saw a GC message well over five minutes into it.  8)

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 05:14:33 PM
Used your recommended settings for the max values and never saw a GC message well over five minutes into it.  8)

Yeah, actually my ad libitum didn't work (I must study MyAlloc+mem manager more closely to tell you why) but 40,000 for heap and 20,000 for stack works. :P

Goto line 1808 to see

Code: [Select]
  IF hpcursor + 3 > maxheapsize THEN
    bsd += 1
    GOSUB GarbageCollect
  END IF

hpcursor is the current heap top pointer. When it grows to maxheapsize-3, it triggers the GC. Recursion is always a very heavy operation, and this garbage collection has too much to do interpretatively in its For/Next loops.

.
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 05:24:12 PM
Remember I'm running 64 bit so numbers and available memory are greater.

I'm thinking of removing the array inits  FOR / NEXT loops and any checks against their max values. Can you see any issue with that?


Garbage Collection:  UNDEF heaptype

This releases the memory used to store the SB array.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 05:40:02 PM
1. You can experiment but don't upload to the repo yet.

2. Try to find the max practical (= allowable) values for maxheapsize and maxstacksize values. Add something to print in the loop (e.g. the x value) to know that all is going well while GC start GC done aren't yet seen. Note however that printing is slow to execute so be patient.

3. The arrays should be released and recreated when the program ends --> this is recursion after all, and the mem structure should stay untouched in the process. If the arrays aren't released at all then the LISP "process" memory will be reusable after the program ends but it will stay bloated as in my picture that I added above. Scriba's footprint was only 2.5MB when it loaded lisp.sb. Everything else is the effect of recursion that expanded the heap array.


At the moment, I have no other info to share. That's where true experimentation/optimization really starts. :)
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 05:46:41 PM
Lets go with numbers that work on your 32 bit box. I don't want something that works for me on Ubuntu 64 bit and not work on someones XP box.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 05:51:34 PM
We can do that in parallel. Or you can put it all on my shoulders only if you send me a 64-bit scriba.exe for Windows. Then I'll be able to test under my x64 Win 7 as well.

But it won't be fair. Huh, imagine me working on a Sunday morning while you're enjoying a cigarette and a few beers in a local bar...  >:(
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 05:56:45 PM
Not a chance. My chains have a limited length. You will not be alone.


As you have said many times, it's still a 32 bit world. I'm good with a SBLisp based on that platform.
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 06:12:50 PM
Quote
you send me a 64-bit scriba.exe for Windows.

Yes sir, see attached.  ???



.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 06:23:30 PM
Quote
you send me a 64-bit scriba.exe for Windows.

C'mon John, you're exaggerating. I wasn't that rude, I said "... if you send me ...". Should it have been "... if you would send me ... please"? :)

Thanks for the zip anyway. Is sb64.exe the scriba I need?

And monitor your forum box please, I'm going to send you a PM soon...
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 06:35:52 PM
You weren't rude. I was playing chop the quote and make up my own response.  ;D

Yes sb64.exe -v will show it's true version info. That version was compiled with the command line C/C++ compiler (VC12) of the same version of Visual Studio we are using. sbw64.exe is the consoleless (Windows version of SB64) that is used with IUP. (theming works)


Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 07:07:22 PM
Thanks again, John. :)

My PM is in your box already.
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 07:12:16 PM
I'm currently under Win 7 64 bit and the first values you gave me that worked with Ubuntu 64 bit works with Windows 64 bit.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 07:17:42 PM
I'm still under XP and my 32-bit info is in your PM box.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 07:33:37 PM
I'm rebooting into 64 bits so I'll be off the air temporarily.
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 07:47:58 PM
Here is my Windows 64 bit rectest.scm. (no GC)

FYI - scriba is 64 bit when C:\sb22_64\bin is in my system path.




.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 08:06:09 PM
John,

These are my results for sb64. Please do use the code and settings as per my PM for consistency.

The dynamics was exactly as I described with a few very nasty near-halts but it somehow survived.

Now I'm going to do the same in WoW64 with scriba.exe to see how it goes on.

.
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 08:17:37 PM
Are these the settings you want me to use?

maxheapsize=40000

maxstacksize = 10000

I actually got a GC with the above settings.

Code: [Select]
C:\Users\John>cd \sb22_64\sblisp

C:\sb22_64\sblisp>sb64 lisp.sb
SBLisp - Scheme BASIC Lisp

0](load 'rectest.scm)
(define rectest (lambda (x)
(cond ((<= x (* 10000)) (rectest (+ x 1))))
))
RECTEST
(rectest 1)
GC start GC done.
GC start GC done.
GC start GC done.
GC start GC done.
()
0]
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 08:25:03 PM
And these are my Win 7 WoW64 results for scriba.exe. Same dynamics but no stop-overs. And it survived the 10001 barrier too! :)

Note the memory footprint as compared to 64 bits.

So, what do we do? If we carry on then I suggest sticking to these heap settings for now. XP will have to abide. ;)


John, is there any chance for malloc()-ed scriba.exe and sb64.exe? If yes then let them be bare, without the other stuff from the distro, and post the zip to my PM box please in order not to disseminate half-baked products. Thank you. :)

It's 7:30 here and I guess I should have some rest. See you later.

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 08:28:16 PM
No John,

400 000 for the heap, 200 000 for the stack. And I'm not kidding. :D

And the script from my PM!

Can you please test it also under Linux if you have time?

Thanks!
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 10:07:37 PM
Code: [Select]
9997
9998
9999
10000
10001
()
(quit)
Bye!

real 11m58.927s
user 10m57.221s
sys 1m0.044s
jrs@laptop:~/sb/sb22/sblisp$

Under Linux the numbers scrolled down the screen consistently without slowdowns or interruptions.  (using above setting with no per-initialization for heap or stack)

I don't see this as real world and more of a stress test of recursion and SBLisp stack / heap banging. I think the answer is to expand on the already working garbage collection system to pre-allocate (FOR/NEXT init) additional elements in chucks of 1K and update the max values accordingly. (up to the  SBLisp system max heap=400K,  stack=200K) This way garbage collection happens less and less as resources are expanded.

I assume you are already doing something like this for FBSL. (REDIM to expand array)



Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 10:54:47 PM
That's correct John.

Recursion is always a stress on system resources, and this is indeed a stress test even if it does little more than just add a 1 to an x.

Batch preallocation can improve the speed dramatically if SB would only allow for something like DIM instead of FOR/NEXT. You should understand that of those 11 minutes spent in user code 10.58 minutes were spent in SB's MyAlloc that was reordering its pieces of pool memory to yield just one array element at a time.

Can we somehow concatenate two similarly structured SB arrays -- one used up, and another one, a fresh batch allocation -- without the need to copy at least one of the arrays on the user side of SB interface, i.e. totally within SB's engine machine code? Something like FBSL's ArrayMerge() function?

Quote
I assume you are already doing something like this for FBSL. (REDIM to expand array)
Yes, DIM[1K]/REDIM PRESERVE[UBOUND+1K] would be the fastest scheme to follow. Upon closer consideration, it would be the most flexible too. This is because FBSL's dynamic arrays, fast as they are, are growable but not shrinkable; you can't UNDEF an FBSL dynamic array. OTOH REDIM and even REDIM PRESERVE work both ways and are fast enough in batch (re)allocation. In one-element-at-a-time (re)allocations however they would work at approximately the same speeds as what we're seeing in SB now.
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 11:12:22 PM
We could drastically reduce the time it takes to create / initialize an array if we were only using single dimension arrays. This would be done with SPLITA which is much faster than a FOR/NEXT init. What this means is we would have to restructure SPLisp to use only single element arrays.  (heaptype /heapvalue  would become 4 arrays instead of two with two additional elements in the second dimension)

We could use SPLITA to define the initial heap and stack arrays at startup and in garbage collection expand them with a FOR/NEXT in chucks increasing the heap or stack in incremental steps which ever caused the GC to occur.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 11:32:40 PM
That's perfectly feasible. Hehe and it will also allow us to reimplement this LISP thingy in at least one more BASIC (guess which) so that Charles could also jump on the bandwagon. :D

So what about concatenation? I remember you used to try and glue two SB arrays together at some earlier stage, didn't you?
Title: Re: Lisp in Basic
Post by: JRS on August 09, 2014, 11:36:51 PM
SB allows tacking on arrays to elements. I can find no way to concatenate a template array to an existing array.  :'(

Expanding (with initialization) a SB array can only be done in a FOR/NEXT.

Maybe we find a sweet spot with SPLITA at startup and let them dynamically expand after that. What is the average stack/heap a typical Lisp script would need?

I'm still trying to spell Lisp.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 09, 2014, 11:49:54 PM
Hmmmm, I rarely use multithreading in my work so I can't recollect off the top of my head if the memory allocated in one thread can be preserved for use in another one once the worker thread exits. If it can then we can theoretically spawn a worker thread to make delayed 1K+ FOR/NEXT preallocations in a non-blocking parallel manner while the main thread continues its routine recursion.

I'm so concerned about recursion because recursion is what the Scheme concept is based upon as opposed to canonical LISP which uses iteration and features all sorts of iterative constructs unavailable in a strict Scheme syntax. Scheme has that for-each iterator only applicable with lambda (user-defined function) callbacks, which doesn't seem very practical from my C- and BASIC-oriented egotistical perspective. :)

I can't answer your question now as I haven't got enough experience in that area. I was planning to study some RosettaCode (http://rosettacode.org/wiki/Category:Programming_Tasks) programming solutions written in Scheme to get a rough idea of what resources might be involved in an average Scheme application...
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 12:08:48 AM
Quote
I rarely use multithreading in my work so I can't recollect off the top of my head if the memory allocated in one thread can be preserved for use in another one once the worker thread exits.

In SB each thread has it's own memory  / variable object. MT allows passing data between threads and has in memory session support of web applications.

I'm going to try and catch a few hours sleep. My vote is for the single array direction which allows more BASIC languages to jump in. (like O2 as you mentioned) If you can convert the two multiple dimension arrays to single dimension arrays, I'll do the SPLITA stuff and then see if dynamic or FOR/NEXT expansions results in better performance. Does GC get called by heap and stack separately or only heap calls GC?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 12:35:58 AM
GC is triggered by the heap top pointer only but the stack and its stack top pointer are also involved in rearrangement in sync with the heap. The stack is also growable.

A GC cycle is a huge piece of CPU- and memory-intensive work to execute so it should be avoided at all costs whenever possible.

So we go the array split and Splita vs. For/Next way. Fine.

Good night, John.
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 12:43:40 AM
Quote
A GC cycle is a huge piece of CPU- and memory-intensive work to execute so it should be avoided at all costs whenever possible.

That sure sounds like a good job for a C based SB extension module.
Title: Re: Lisp in Basic
Post by: RobbeK on August 10, 2014, 01:05:17 AM
Hi all,

It seems this Scheme is missing the standard itertive mechanism (do ....   )  ? identical with Common Lisp and powerful.

An example from something written yesterday (Bigloo Scheme)

-----------------------
(do ((i 0 (+ i 1)))
                   ((= i (vector-length vec)))
                     (j_drawline cs i 400 i (- 400 (vector-ref vec i))))
----------------------

first line initiates the local(s) and the step  , second the end condition, 3rd the body , without this coding will be somewhat difficult ...

best, Rob
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 01:15:05 AM
FOR / NEXT array initialize
Code: [Select]
FOR x = 0 to 99999
  a[x] = 0
NEXT x
PRINT UBOUND(a),"\n"
jrs@laptop:~/sb/sb22/sblisp$ time scriba fornext.sb
99999

real   1m26.954s
user   1m14.281s
sys   0m12.501s
jrs@laptop:~/sb/sb22/sblisp$

SPLITA create / initialize
Code: [Select]
SPLITA STRING(100000,"0") BY "" TO a
PRINT UBOUND(a),"\n"

jrs@laptop:~/sb/sb22/sblisp$ time scriba splita.sb
99999

real   0m0.033s
user   0m0.024s
sys   0m0.008s
jrs@laptop:~/sb/sb22/sblisp$

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 02:07:19 AM
@Rob:

Thanks for reminding me about (do). In fact I'm keeping it in mind. I'm simply waiting for when John finds a little time to get acquainted with the Scheme vocabulary to tell me that there's no (print) in there but rather (display), and that there's not only (for-each) in there but also (do). :)


@John:

Splita does seem very impressive!

In the meantime, I want you to have a look at the picture below. I'm not showing off or something. It's just FYI. I've split the FBSL 2-dimensional arrays into 4 separately declared but not dimensioned dynamic arrays (i.e. for example DIM HEAPvalue[]) that are similar in their behavior to what your growable arrays now do. But mine are doing all this bloody damn faster! Incongruously faster! Look at the results: 5.5MB is the starting memory footprint, 12MB only is the ending footprint, and a mere 10 seconds to complete the interpretative recursive evaluation proper.

My maxheapsize is set to 4 000 000 and my maxstacksize is set to 2 000 000.

This is very difficult for SB to beat. But we must find a way to move as close to it as possible. Let's keep our fingers crossed.

Now to bed. Both of us. We need all the power there is. :)

.
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 08:27:05 AM
Quote
I'm not showing off or something.

SB and FBSL variables are like comparing apples and oranges. SB variables are like variants. (objects) SPLITA is the fastest way (at the user level) to create arrays (single dimension) in SB. It seems that once the array is built, accessing elements seem as quick as accessing any other SB variable type. We are using SB in the development phase for the following reasons. Once this works there will be multiple BASIC options to choose from (SB, FBSL, O2, ...) for your Scheme Lisp projects.


There will be no claims from me  that SB is the fastest or most feature rich BASIC in the SBLisp offerings. On the Windows platform I think it will be you and Charles in the speed/feature race, not SB. If you have a better suggestion of a BASIC to use to develop SBLisp, I'll follow along and maybe learn something new as well.




Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 09:02:14 AM
You got up on the wrong side of the bed, John.

Please let me know:

1. where I can read up on SB's SWAP command; and

2. if I can still have a pair of malloc()-based scriba.exe+sb64.exe for Windows from you.

I don't need anything else currently to continue my research of SBLisp on my own. As soon as I'm through with it, I will make my results and suggestions available publicly or privately following your advice on this particular matter. I guess this will be the best suggestion I can offer.


Thanks!
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 09:10:12 AM
Mike,

Just showing that you have some interest in SB and willing to give it a try is more than I could have ever hoped for. Your evaluation of Script BASIC will go a long way and if positive, maybe be others will add it to their programming toolbox.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 09:16:20 AM
Where did you hear me say I was going to evaluate ScriptBASIC? I said I'm going to research Es-Bee-Lisp. This isn't the same as FBSL LISP or OxygenLisp as soon as the latter is ready. Neither FBSL LISP nor OxygenLisp depends, or will depend, on SBLisp for their own evolution.

Just give me an answer to my questions, please. This is all I would like to know at the moment.

Thanks again!
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 09:22:52 AM
Quote
Where did you hear me say I was going to evaluate ScriptBASIC?

Oops. I misread SBLisp as Script BASIC. My comment still stands.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 09:26:48 AM
REPEAT

Just give me an answer to my questions, please. This is all I would like to know at the moment.

UNTIL GOTTEN
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 09:55:24 AM
Strange that the SWAP function isn't documented. Here is what I was able to find in the source. Pay special attention to the point of REF and it using the real variable and not the reference to it. If not using REF, just ignore my warning.

Code: [Select]
This command swaps two variables.

*/
COMMAND(SWAP)
#if NOTIMP_SWAP
NOTIMPLEMENTED;
#else
  LEFTVALUE VariableA,VariableB;
  pFixSizeMemoryObject VSWAP;
  long refcount;

  /* we get the pointer to the variable that points to the value */
  VariableA = EVALUATELEFTVALUE(PARAMETERNODE);
  ASSERTOKE;

  /* if this points to a reference value then we search the "real" variable
     to modify */
  DEREFERENCE(VariableA);

  /* get the next parameter of the command, which is the other variable */
  NEXTPARAMETER;

  /* we get the pointer to the variable that points to the value */
  VariableB = EVALUATELEFTVALUE(PARAMETERNODE);
  ASSERTOKE;

  /* if this points to a reference value then we search the "real" variable
     to modify */
  DEREFERENCE(VariableB);

  VSWAP = *VariableA;
  *VariableA = *VariableB;
  *VariableB = VSWAP;

#endif
END

I don't have a non-multi-threaded version of scriba.exe compiled nor have I created one in the past. I will work on  this as I'm also interested in the performance difference if SB is compiled as a single threaded process. (no MyAlloc routines used)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 10:16:28 AM
Thanks John,

This information on SWAP() will largely suffice. I was wondering what it would do if the arguments were arrays. FBSL SWAP() would swap array pointers. Now I know that SB SWAP() would do the same. It enables me to split the SB arrays in the exact same programmatic way as I did in FBSL.

I would greatly appreciate your effort to recompile SB without multithreaded support. Just let me know when or if you have secceeded. This won't however slow down or suspend my current research plan.
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 10:27:08 AM
Here are the Script BASIC keywords as defined in the code. Some aren't implemented and others undocumented but in either case they shouldn't be used as variable names.

Code: [Select]
ISINTEGER
ISNUMERIC
ISDEFINED
ACOSECANT
HCOSECANT
FILEOWNER
TIMEVALUE
ADDMINUTE
ADDSECOND
RANDOMIZE
DIRECTORY
ISSTRING
COSECANT
INSTRREV
FREEFILE
NEXTFILE
ENVIRONS
ADDMONTH
HOSTNAME
TEXTMODE
FUNCTION
TRUNCATE
CLOSEALL
FILECOPY
ISARRAY
ISUNDEF
ISEMPTY
ASECANT
HSECANT
STRINGS
REPLACE
FILELEN
ENVIRON
COMMAND
ADDRESS
WEEKDAY
YEARDAY
ADDYEAR
ADDHOUR
ADDWEEK
EXECUTE
WAITPID
BINMODE
DELTREE
SPLITAQ
PRINTNL
DECLARE
PATTERN
MAXINT
MININT
STRING
LBOUND
UBOUND
ISREAL
COTAN2
SECANT
UCASES
UPPERS
LCASES
LOWERS
LTRIMS
RTRIMS
RIGHTS
SPACES
OPTION
ERRORS
ISFILE
CURDIR
FORMAT
GMTIME
MINUTE
ADDDAY
SYSTEM
REGION
OUTPUT
DELETE
REPEAT
UNPACK
MODULE
SPLITA
ELSEIF
RESUME
GLOBAL
RETURN
REWIND
BYVAL
FALSE
UNDEF
ROUND
LOG10
UCASE
LCASE
LTRIM
RTRIM
RIGHT
SPACE
JOKER
CHOMP
ACTAN
COTAN
HCTAN
UPPER
LOWER
TRIMS
LEFTS
INSTR
ERROR
INPUT
MONTH
ICALL
CRYPT
PRINT
CONST
LOCAL
ELSIF
CHDIR
MKDIR
GOSUB
PAUSE
QUOTE
ENDIF
SPLIT
ALIAS
CLOSE
RESET
WHILE
UNTIL
SLEEP
LIKE
ASIN
ACOS
EVEN
TRUE
CINT
FRAC
MKDS
MKIS
MKSS
MKLS
TRIM
LEFT
TYPE
ATAN
HCOS
HSIN
HTAN
TAN2
MIDS
CHRS
STRS
HEXS
OCTS
JOIN
IMAX
IMIN
PACK
TIME
YEAR
HOUR
CONF
KILL
FORK
WEND
FILE
LOOP
SWAP
LINE
NAME
OPEN
FROM
WILD
THEN
NEXT
LOCK
EXIT
STEP
ELSE
NULL
GOTO
CALL
ELIF
STOP
SEEK
AND
XOR
NOT
SIN
COS
SGN
ODD
GCD
LCM
SQR
RND
ABS
VAL
FIX
INT
CVD
CVI
CVL
CVS
MKD
MKI
MKS
MKL
LOG
POW
EXP
LEN
ASC
MID
CHR
STR
HEX
OCT
RAD
ATN
TAN
BIN
MAX
MIN
LOC
LOF
EOF
EOD
NOW
DAY
SEC
REF
VAR
SET
POP
LET
FOR
END
LIB
SUB
OR
PI
IF
ON
DO
TO
NO
BY
GO
AS
GMTIMETOLOCALTIME
LOCALTIMETOGMTIME
FILEACCESSTIME
FILEMODIFYTIME
FILECREATETIME
STRREVERSES
ISDIRECTORY
STRREVERSE
FILEEXISTS
FORMATDATE
FORMATTIME
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 10:41:30 AM
Code: [Select]
' Mike's SWAP array test

a[0]=0
a[1]=1
a[2]=2

b[0]=2
b[1]=1
b[2]=0

SWAP a, b

PRINT a[0],"\n"
PRINT a[1],"\n"
PRINT a[2],"\n"

jrs@laptop:~/sb/sb22/sblisp$ scriba swaparray.sb
2
1
2
jrs@laptop:~/sb/sb22/sblisp$

Code: [Select]
a = 1
b = 2

SWAP a, b

PRINT "A: ",a,"\n"
PRINT "B: ",b,"\n"

jrs@laptop:~/sb/sb22/sblisp$ scriba testswap.sb
A: 2
B: 1
jrs@laptop:~/sb/sb22/sblisp$

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 11:08:51 AM
Grrrrrrr, yeah I've bumped into that already. >:(

Another easy alternative would be if SWAP() would swap correctly the pointers stored in two REF variables that refer to (alias) the both arrays... But something's telling me it wouldn't... :-\
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 11:33:59 AM
Wrong! It would! :)

Code: [Select]
a[0]=0
a[1]=1
a[2]=2

b[0]=2
b[1]=1
b[2]=0

PRINT "------------\n"
PRINT a[0]," ",a[1]," ",a[2],"\n"
PRINT "------------\n"
PRINT b[0]," ",b[1]," ",b[2],"\n"
PRINT "------------\n"

ref c = a
ref d = b

SWAP c, d

PRINT a[0]," ",a[1]," ",a[2],"\n"
PRINT "------------\n"
PRINT b[0]," ",b[1]," ",b[2],"\n"
PRINT "------------\n"

.
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 11:38:23 AM
SB is full of surprises and the best part is I haven't run into any limitations yet that would prevent me from continuing using it.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 11:51:47 AM
You don't have to put up your defences, John. Nobody's on the offensive side here. This isn't the FreeBASIC forum after all.
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 12:03:13 PM
No defenses intended. SB speaks for itself. I was just expressing my personal experience with the language.,
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 12:24:21 PM
Every single BASIC-er around the globe knows your attitudes. No need to repeat yourself over and over again. So let's consider this matter settled once and for all at least between us two, OK?

Now please tell me if there's any way for SB to load an STDCALL function directly from a Windows stock DLL without writing a wrapper for it?
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 12:40:45 PM
Quote
No need to repeat yourself over and over again.

Great! Mike says the SB house isn't haunted and there are no ghosts. Peter Verhas truly is the hero here.

You have two choices. DYC (Peter's simple FFI) or Charles's DLLC which is FFI + on steroids. Both are 32 bit Windows only extension modules.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 12:49:00 PM
Peter Verhas truly is the hero here.

Under your wakeful eye, John.

Where do I find this DLLC wonder, please?
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 01:06:52 PM
DLLC is part of the OxygenBasic WIP ZIP builds. See projectB\ScriptBasic.

I will put my Windows SB 2.2 source on the server for you to download. I will send you the link via a PM. I don't want pre-released SB 2.2 source floating around. The available 2.1 source would work fine but I'll send you current as you're a BASIC developer.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 01:17:06 PM
Oh, you're so very kind John.

And, er, actually I am the BASIC developer. ;)
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 04:01:18 PM
Quote
And, er, actually I am the BASIC developer.

Are you saying that FBSL is now you're baby? (single developer effort)



Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 06:15:09 PM
Mike,

I have been doing more testing of SBLisp and ran into another issue. Personally I would like to see F rather than () for false.

SBLisp
Code: [Select]
0](< 2 3)
()

mit-scheme
Code: [Select]
1 ]=> (< 2 3)

;Value: #t

Interesting that this does work.
Code: [Select]
0](<= 2 3)
T
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 10, 2014, 06:57:01 PM
Are you saying that FBSL is now you're baby? (single developer effort)

Never mind, John. It was meant to convey a shade of pique.

No, we are a team to the end of FBSL time. We are all human and it's just that everyone has their own rises and pitfalls from time to time. We shall overcome.

Mike,

Personally I would like to see F rather than () for false.

I might cure your pain, John, well, some day. Hence the definite article.

Hehe, and a coup de grace:

.
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 07:09:49 PM
Outstanding!

Another member of the Lisp in BASIC family.  :)

P.S. Not to underscore Charles's LeanLisp efforts.
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 07:49:38 PM
The greater than doesn't work either.  :-\

SBLisp
Code: [Select]
0](> 2 1)
()
0]

mit-scheme
Code: [Select]
1 ]=> (> 2 1)

;Value: #t

1 ]=>
Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 08:10:24 PM
I fixed it. The compares were reversed.

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
SBLisp - Scheme BASIC Lisp

0](< 2 3)
T
0](> 2 1)
T
0](quit)
Bye!
jrs@laptop:~/sb/sb22/sblisp$

I also fixed the ATAN function. The ATN keyword is reserved but not implemented in SB. I replaced it with ATAN which is one of the new math functions Tom added for the SB 2.2 release.

Code: [Select]
0](atan 1)
0.785398
0]

Changes

3010  IF pvalue < qvalue THEN

3044  IF pvalue > qvalue THEN

3203    rvalue = ATAN(rvalue)

Fixed code pushed to Bitbucket.

I have gone through the complete Lisp in BASIC documentation trying the examples presented. Everything seems to work at this point from what I can tell.

Title: Re: Lisp in Basic
Post by: JRS on August 10, 2014, 10:03:24 PM
I went ahead an did the conversion of the heaptype and heapvalue arrays. I have to say that the difference with Mike's benchmark is amazing and I have a heap of 400000 and stack of 200000 before garbage collection is being done. I'm happy! (12 minutes to 10 seconds)  8)

Code: [Select]
9998
9999
10000
10001
()
(quit)
Bye!

real 0m10.187s
user 0m9.641s
sys 0m0.468s
jrs@laptop:~/sb/sb22/sblisp$

Old Method
Code: [Select]
9997
9998
9999
10000
10001
()
(quit)
Bye!

real 11m58.927s
user 10m57.221s
sys 1m0.044s
jrs@laptop:~/sb/sb22/sblisp$

Attached is the FBSL version of this.


.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 04:01:37 AM
Hi John,

It is very strange to see the < and > bugs survive because they were fixed as early as on August 7. You can see it by the date of this message (http://www.fbsl.net/phpbb2/viewtopic.php?f=26&t=3028#p10562) on the FBSL forum. Perhaps something went wrong that night when we were pushing the code up and down the repo prior to working out a common plan.

Thanks for the ATAN fix. It slipped me 'cause of SB not barking up the ATN tree.

1. Now I'll be dowloading your code from the repo; I want to see how you split the arrays. I'm glad it works but for the sake of maximum unification I suggest doing it my way because I did it for SB, FBSL and O2 already.

2. We have yet to see a case where garbage collection interferes with calc speed, functionality, or precision. So my suggestion is to subside to 20 000 for the heap, and 10 000, for the stack, in all the 3 languages. Under these conditions, the recursive stress test runs in 8 sec for SB, 9 sec for FBSL, and X millisec for O2 (still crashes, in fact). The memory footprints at these settings are also very similar between SB and FBSL.

Please give me an explicit answer if you (dis)agree with these two propositions.

I'll be working to fix OxyLISP to full usability today and see how it behaves under this stress test. Once through with it, we'll discuss where to go further.
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 06:52:02 AM
I haven't seen your way of splitting the array yet so I hope you are good with the way I did it for SBLisp.

I'll change the max setting per your suggestion.

Have you run any test with what I posted?

Code: [Select]
1092
1093
1094
1095
1096
GC start A broken heart.

real 0m1.289s
user 0m1.132s
sys 0m0.036s
jrs@laptop:~/sb/sb22/sblisp$

Seems I broke something with GC in the array conversion. (using the new heap and stack max values)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 07:25:57 AM
I am good with anything that works. But what about the code consistency? It'd be easier for me to maintain three versions at once.

Alternatively, I can suggest my working with the SB code the way I please and uploading my developments here from time to time for you to decide what is good and/or fit for the repo version that you're maintaining.

No, I haven't yet touched the SB code today except for fixing the bugs you mentioned above, in my local copy. I'm all into galvanizing OxyLISP. This strict data typification is driving me mad. I can't get floating-point math to work yet. Matter is rvalue, pvalue, etc. are reusable in QB, SB, and FBSL for all sorts of calc but it can't be mimiced easily in O2 where typification either rounds everything to integers or unrolls it to doubles... >:(

Here's my latest lisp.sb. But be careful -- it may be non-conformant with your formating specs.

.
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 08:09:36 AM
Mike,

Your version of SBLisp works and gives better numbers to boot. I'm good with your version for SBLisp. I will do a little testing and push it to Bitbucket.

Code: [Select]
9997
9998
9999
10000
10001
()
(quit)
Bye!

real 0m9.455s
user 0m9.133s
sys 0m0.252s
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 08:50:44 AM
Mike,

I have pushed your slightly cleaned up version of SBLisp to Bitbucket.  I'm calling this the MASTER at this point.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 09:19:18 AM
Thanks, John.

Faster boot is due to heap/stack sizes set to 20000/10000. SPLITA() takes its toll on large arrays too though it works really much faster than FOR/NEXT. I wasn't able to find an alternative way to do anything with the arrays.

Also, it looks like the internal representation of an array element in SB is rather memory consuming. Setting the max heap size to 4M would produce a 250MB array in SB against some 80MB in FBSL. It would also render the boot time intolerably long. So I confined the max sizes to 20000/10000 in all languages and let CG do its work whenever necessary, which made them boot almost equally fast subjectively.

I suggest we postpone further recursion depth investigations till we come across a case when it really matters to the viability of an actual LISP application.
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 09:39:08 AM
Great job by the way. You're definitely a PRO!!!

I will try to find some Scheme based Lisp examples to try and see if I can break SBLisp.

Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 10:20:00 AM
@Mike - Can you have a quick peek at this an let me know what might be causing the read error?

Quote
The purpose of the following function is to help balance a checkbook. The function prompts the user for an initial balance. Then it enters the loop in which it requests a number from the user, subtracts it from the current balance, and keeps track of the new balance. Deposits are entered by inputting a negative number. Entering zero (0) causes the procedure to terminate and print the final balance.

Code: [Select]
(define checkbook (lambda ()

; This check book balancing program was written to illustrate
; i/o in Scheme. It uses the purely functional part of Scheme.

        ; These definitions are local to checkbook
        (letrec

            ; These strings are used as prompts

           ((IB "Enter initial balance: ")
            (AT "Enter transaction (- for withdrawal): ")
            (FB "Your final balance is: ")

            ; This function displays a prompt then returns
            ; a value read.

            (prompt-read (lambda (Prompt)

                  (display Prompt)
                  (read)))

            ; This function recursively computes the new
            ; balance given an initial balance init and
            ; a new value t.  Termination occurs when the
            ; new value is 0.

            (newbal (lambda (Init t)
                  (if (= t 0)
                      (list FB Init)
                      (transaction (+ Init t)))))

            ; This function prompts for and reads the next
            ; transaction and passes the information to newbal

            (transaction (lambda (Init)
                      (newbal Init (prompt-read AT)))))

; This is the body of checkbook;  it prompts for the
; starting balance

  (transaction (prompt-read IB)))))

Output
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
SBLisp - Scheme BASIC Lisp

0](load 'ckbook.scm)
(define checkbook (lambda ()
        (letrec
           ((IB "Enter initial balance: ")
            (AT "Enter transaction (- for withdrawal): ")
            (FB "Your final balance is: ")
            (prompt-read (lambda (Prompt)
                  (display Prompt)
                  (read)))
            (newbal (lambda (Init t)
                  (if (= t 0)
                      (list FB Init)
                      (transaction (+ Init t)))))
            (transaction (lambda (Init)
                      (newbal Init (prompt-read AT)))))
  (transaction (prompt-read IB)))))
CHECKBOOK
 
ERROR: Read.
ERROR: Problem in file ckbook.scm
0]
 

My guess. transaction isn't a SBLisp symbol. :-(

mit-scheme
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ mit-scheme
MIT/GNU Scheme running under GNU/Linux
Type `^C' (control-C) followed by `H' to obtain information about interrupts.

Copyright (C) 2014 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Image saved on Saturday May 17, 2014 at 2:39:25 AM
  Release 9.2 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || Edwin 3.116

1 ]=> (load 'ckbook.scm)

;The object ckbook.scm, passed as an argument to merge-pathnames, is not a pathname.
;To continue, call RESTART with an option number:
; (RESTART 1) => Return to read-eval-print level 1.

2 error> (load "ckbook.scm")

;Loading "ckbook.scm"... done
;Value: checkbook

2 error>


Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 10:53:45 AM
There ain't no such command as (letrec) in SBLisp. According to the PDF, there are only (let) and (let!) in its vocabulary. This code needs rework based on what (letrec) actually does in the dialect this app was originally written in.

It also uses other non-existent commands, e.g. (display) which is actually (print) in SBLisp and its siblings.

SBLisp is currently rather limited in its functionality. I think the only problems it can theoretically solve would be the simpler tasks published at the Rosetta Code site I pointed you to earlier in this thread. And even those would require rework to fix up (define ... (lambda ...)) declarations and (print) statements. There's no explicit functionality either for interactive input similar to (read) in your alien LISP code.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 11:39:26 AM
Hello John,

Based on Charles' input in this thread (http://www.oxygenbasic.org/forum/index.php?topic=1163.msg10446#msg10446), we're in some trouble with the OxyLISP implementation modeled after SB and FBSL, in particular with the array SWAP() trick.

I will have to turn all its inner maths and storage to explicit doubles or the trick won't work. I could of course introduce yet another array to track the required data types and apply the corresponding casts to raw data all along, but that would deviate OxyLISP's structure very far from its SB and FBSL siblings.

Naturally enough FPU calc will be way slower compared to integer calc by machine code standards. Yet it'll remain lightning fast against our interpretative realities.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 11, 2014, 11:46:54 AM
Would variants help? SB uses int/double/string within its variant construct.
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 12:39:48 PM
Quote
There ain't no such command ...

That reality became all to clear as I investigated the code closer. Maybe Rob can chip in with testing of SBLisp / FBSL Lisp or QxyLisp when it works?

I like Charles's idea of using variants.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 01:01:37 PM
Quote
SB uses int/double/string within its variant construct.

... and the FBSL Variant object covers 44 possible data types being almost fully COM-compliant. But that would inevitably require all the concomitant decor unnecessary for SB and FBSL lisps. <shrug> OxyLISP as yet another lifelong variant-based commitment... </shrug>

Adding just another array for data type tracking and associated casting seems simpler. Yet it would already take the projects too much apart structurally. Why not just subside to doubles only? We're not challenging near-light speeds with BASIC LISP's existing design principles anyway...
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 11, 2014, 01:45:20 PM

Oxygen has quite good auto-type-conversion, including double to string and vice-versa. It certainlysimplified codong LeanLisp, so you may find there is less adaptation work to do than you think. As long as the variable types are not anonymised, Oxygen will take care of most conversions within expressions and procedure calls.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 03:00:08 PM
Regretfully they are, Charles. String data such as SYMBOLs (keywords, names and literals) are stored in a hash table while numeric data is stored in variant arrays (QB/SB/FBSL). The "registers" and temporary variables that store and access this data are all variant-based too, and they also serve the needs of creating, replenishing and accessing the hash table at the same time.

I cannot avoid anonymizing the heap arrays because the setup uses heap "page" swapping (two separate arrays corresponding to two "pages" of heap memory). Swapping occurs in the garbage collection cycle. It was initially implemented in QB45 as a two-dimensional variant array with its second dimension being "pages" 0 and 1, respectively. "Page" swapping was organized by swapping the values 0 and 1 in the indexer variables ACTIVE and PASSIVE.

On splitting the arrays, the only option I was left with was swapping distinct array pointers rather than the second dimension indexers. That was achieved by direct
Code: [Select]
SWAP(active_array, passive_array) in FBSL, and by somewhat more elaborate ref vars in SB:
Code: [Select]
REF active_array = array0
REF passive_array = array1
SWAP active_array, passive_array

Now you've helped me determine the most efficient way to do the same in OxyLISP but it doesn't withdraw the issue with strong data typification of the arrays from the agenda.

Hence my suggestion to move over to doubles. Once the arrays and their overlays are strong typed to double, I can still use their values for hardcoded hash table access through appropriate type casts to ints of various sizes. But I can't still foretell exactly what data type a temporary variable would have when it is supposed to go into a "register", or heap location, or stack location. I have to keep track of current data type in every temp var and use appropriate casts. I am also supposed to build a hellish IF/THEN/ELSE tree in almost every other statement to evaluate for possible data types in each "register", heap, and stack location.

This is provided for free under the hood in SB and FBSL but it would be hardly worth the effort in OxyLISP which is nothing but a toy yet, exactly like its variant-based interpretative siblings. :)

This is why my vote is for doubles only.

BTW not only is this GOSUB/RETURN/RET trickery very unattractive as it is but it would also be even more ugly to re-work into SUB/RETURNs. Three quarters of the existing labels are referred to with both GOTO and GOSUB. Go figure how to deinterlace all this mess when you're nearing your sixties and doubting whether it's all worth the effort ... :(
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 03:24:00 PM
I wonder what this would look like in C or C BASIC? Is C's goto/gosub usable in a program like SBLisp?

Q. Is there a difference between PROCEDURE (Scheme) and PROCEDURE? (as in SBLisp)

I think we need a Lisp in BASIC translation table to mit-scheme syntax. At lease that would show us where the holes are.

@Mike - How did you end up solving your memory leak in FBSL?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 03:42:50 PM
This code works in O2 where GOTO/GOSUB/RET resolves into asm jmp LABEL/call LABEL/ret directly. QB45, SB and FBSL mimic this behavior for variant variables programmatically in their respective engines. The C language however has only a goto option that resolves to an asm jmp directly. C would normally expect a callable pointer implemented as a fully qualified function call and a lot of type-cast trickery would be involved in setting up gosub-like pseudo-function calls to otherwise goto-able labels. Not every C compiler out there would even support such functionality at all (FBSL's DynC does, actually).

This is why I preferred to start with OxyLISP before I would be taking a decision if rewriting this in CBASIC/C/DynC would be worth the effort again.
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 03:47:36 PM
Quote
Go figure how to deinterlace all this mess when you're nearing your sixties and doubting whether it's all worth the effort .

For me, learning (Scheme) Lisp from under the covers is similar to how I learned C by supporting SB. I'm looking forward to adding extension module support to SBLisp.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 04:08:07 PM
All SBLisp's built-in procedures (i.e. commands) ending in a question mark are actually polls of the corresponding state: EQ? ==> is equal to?, NUMBER? ==> is a number?, PROCEDURE? ==> is an internal procedure or user-defined lambda?, etc. etc. etc. By the same token, any LISP keyword with a trailing question mark yet unavailable in SBLisp should follow the same pattern.

By the looks of it, PROCEDURE without a trailing question mark should rather be a declaration supposedly similar to LAMBDA but probably of a different syntax. But that'd be more a wild guess than a statement.

Let the BASIC LISP syntax be similar to any known Scheme implementation, preferably wide spread enough to supply a noticeable and alive enough user base. But the decision should be taken now, at the early stage of development because it will have significant impact on the internal structure and will be difficult enough to unwind should anything go wrong with it.

You should also be assured that the LISP you're going to take after has everything you might want for your creation. You will not be supposed to invent your own syntactical crutches for a mature dialect. For example, if there is enough in this mit-scheme you're suggesting in the way of GUI that you're planning to implement yourself, then let it be mit-scheme. Otherwise let it be that very Scheme which Rob used for his Monte Carlo gambling. But let's not turn it into a mit-Carlo bastard.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 04:19:51 PM
I left the FBSL memory leak issue open for the time being for the sake of code unification. The leak is small and manifests itself only in deep recursion patterns. If I didn't mention it, you would hardly ever notice it existed.

We have more urgent matters now to attend to. Now that the entire vocabulary of BASIC LISP is usable and correct (you reported it after going through all the PDF examples), we should take a decision which way to go syntactically and start to remodel the existing functionality and develop new one according to our choice.

Within a short period of time, we should be able to run standard console LISP examples in an easy and natural way to be able to explore the yet unknown limitations of BASIC LISP on something better than a trivial recursive count from 1 to 10001. :)

This is our immediate goal.
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 04:20:35 PM
I would like to hear Rob's evaluation of SBLisp (standalone 32 bit Windows version attached) and let us know if it could be a good foundation to expand on. I would like to get Rob weaned off JAPI and onto to SDL_gfx (his comment was it had everything he needed an more) which is just a syntax integration into SBLisp. Doing this in BASIC makes it doable in our remaining lifetime.

P.S. - SBLisp.exe is also available on the Bitbucket repository. (same zip)


.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 04:38:24 PM
Rob is a mathematician and everything greater than 10E-127 decimal places of precision and longer than 10E-127 seconds to execute is non-existent to him.

We should yet develop our projects first to an extent when they might even potentially interest him to fiddle with.

:D
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 05:23:16 PM
Mike,

You are the lead for this project and I'll follow along supporting the SBLisp side of this as long as there is interest in it by others.

Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 09:47:53 PM
Mike,

I was looking at the old QB code and it looks like SWAP is only swapping the variables ACTIVE and PASSIVE which are INTs not arrays. I don't see how the QB swap converts all the elements in the array (second element) during GC. Is the QB version just changing 'polarity' leaving the GC routine?

QB SWAP

NAME
  SWAP Statement

SYNOPSIS
  SWAP variable1, variable2
      o variable1 and variable2    Two variables of the same data type.

DESCRIPTION
  Exchanges the values of two variables.

  Example:
      a% = 1: b% = 2
      PRINT "Before: "; a%, b%
      SWAP a%, b%
      PRINT "After: "; a%, b%
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 10:18:07 PM
Thanks John.

So here's one more strategic decision to take.

We should realise that both SB and FBSL are now dealing with an interpreter implemented in an interpretative language. This is interesting and instructive but quite weird and uninspiring, speed-wise.

Let's take another recursive example from the Rosetta Code site that computes Fibonacci numbers up to the 26th number in the topmost Fibonacci sequence here (http://en.wikipedia.org/wiki/Fibonacci_number).

The algorithm uses two child recursions in each parent recursion so that the recursive tree grows deeper and deeper as the span of possible numbers to evaluate becomes broader with each next number to find following those already found. This is a very serious stress test to verify the integrity of memory management in a language. Both SB and FBSL LISPs pass it successfully, but!

A static or JIT compiler would do this blazing fast even for a much larger Fibonacci number while the 26th number will be found so fast that the benchmark won't be even registered with the Windows system tick timer.

We can assume that both Oxygen and FBSL's DynC JITs are equally fast and very close to static compilers. So the Fibonacci function written directly in either of them can be taken for reference. Please take a look at the leftmost picture below. It implements this function in C and tries to benchmark it as it runs in JIT-compiled machine code. It will run just a little faster in a true optimizing static C compiler like VC or GCC.

Next we can roughly assume that SB and FBSL have equally fast BASIC interpreters. Have a look at the middle picture below. It implements a verbatim equivalent to the function used in the C benchmark above but rewritten in FBSL BASIC. You can easily translate this code to SB to see the SB results on your machine. Or you can use it for equivalent Oxygen code to verify JIT BASIC speeds compatible to my JIT C above.

And finally, we can roughly assume that our LISPs are also equal in their potential at their current internal settings. So now have a look at the rightmost picture. It presents a verbatim equivalent rewritten in BASIC LISP (I'm always using this term to denote its three current implementations in SB, FBSL, and O2 at once). You can try it on your SBLisp on your machine too to the same effect if you're patient enough. And we'll be also able to test it in OxyLISP as soon as its GC is fully functional. OxyLISP will be showing the results very close to what we have for interpreted SB and FBSL in the middle picture below. No wonder: it will be an interpretative LISP with an engine running in true machine code.

We will never be able to achive OxyLISP results in both SB and FBSL LISPs as we know them now. They are no match for the former. Hehe OxyLISP will be a good match for SB and FBSL BASICs instead.

So we should take a strategic decision now what is reasonable to do in the future. My current opinion is as follows:

-- OxyLISP can continue its development based on the code at hand;
-- FBSL LISP should be rewritten in DynC and therefore go fully C compliant; and
-- SBLisp should be rewritten in CBASIC where possible and utilize verbatim C inlines where not, i.e. inherit the best of the two worlds.

What else can we do so as not to be wasting our time for nothing? I do not know.

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 10:31:22 PM
John,

QB45 swaps the values in the variables that are used to address the two indices (0 and 1) of the second dimension in the two-dimensional heap value and type arrays.

Since the arrays are now split, there are no indices left to swap the arrays with. They have no point of connection any more. The only way out is to swap the pointers that refer to the array heads, i.e. their respective leading elements. In FBSL, these are array references themselves (values stored under their names, if you want) while in SB, these are the values in ref variables that are storing the pointers to these arrays.

We were lucky enough to have SWAP(array,array) or its equivalent in all the three languages. Otherwise I would've given up immediately even before array splitting. That's because one must be completely out of one's mind to even think of anything that would resemble Aurel's "solution" to the problem even remotely.
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 10:35:31 PM
There are plenty or Lisp interpreters and compilers out there. I'm not looking to compete with them or even FBSL / O2. I'm more interested in merging the strong points of SB with SBLisp. (ext. module support, symbol standardization, and optimization last)

SBLisp = Toy  Lego / Erector Set BASIC tools to build a custom version of Lisp and maybe solve some of its short comings.

Quote
We were lucky enough to have SWAP(array,array) or its equivalent in all the three languages. Otherwise I would've given up immediately even before array splitting. That's because one must be completely out of one's mind to even imagine anything that would resemble Aurel's "solution" to the problem even remotely.

I don't know about that boy. It's gotten to the point I have to leave him in the car when going out in public. I think it's your turn to watch him for awhile.
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 10:49:15 PM
Arthur Nunes-Harwitt

(http://www.cs.rit.edu/pictures/people/faculty/anh.jpg)

Biography

Arthur Nunes-Harwitt received his bachelor's degree in Computer Science from Brandeis University. He went on to receive masters' degrees in both Mathematics and Computer Science from the University of Pittsburgh, and is ABD in Computer Science at Northeastern University. He has worked as a software engineer at the Learning, Research and Development Center in Pittsburgh and at The Mathworks, and has taught at the Wentworth Institute of Technology and at SUNY Nassau Community College. His interests include the design and implementation of LISP-like languages, artificial intelligence, and computer algebra.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 10:52:29 PM
SBLisp = Toy
?
Quote
Lego
? ?
Quote
Erector Set
? ? ?
Quote
...solve some of its short comings.
Like what for example? What problems can you solve using a tool that is exactly one thousand times slower than the finely tuned mechanism you're so set to repair?! John, SB and FBSL are only some 120 times slower than VC or GCC. SB/FBSL LISPs are yet an order of magnitude slower than this compared to their SB and FBSL hosts!

Quote
I don't know about that boy. It's gotten to the point I have to leave him in the car when going out in public. I think it's your turn to watch him for awhile.
Have a look here (http://www.oxygenbasic.org/forum/index.php?topic=1163.msg10455#msg10455). I was literally begging this ... ... ... to stop sh... ...ting in my thread before the addressee even has a chance to respond. All in vain. ... ... ... ...!
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 11, 2014, 10:58:34 PM
Gosub is implemented in Oxygen. It translates directly to call label.
To terminate a gosub, ret must be used, rather than return.
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 11:02:07 PM
Doesn't seem to work for me.

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
SBLisp - Scheme BASIC Lisp

0](define fibonacci (lambda (n)
2](if (( n 2)
4]n
4](+ (fibonacci (- n 1))
5](fibonacci (- n 2)))))
2])
1])
FIBONACCI
0](fibonacci 26)
ERROR: Bad type in car.
0]
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 11:02:58 PM
Gosub is implemented in Oxygen. It translates directly to call label.
To terminate a gosub, ret must be used, rather than return.

Morning Charles! :)

Yes, we know. We have used them in our OxyLISP 48 hours ago. It would've been impossible to survive without that valuable and indispensable feature in OxygenBasic, ScriptBASIC, and FBSL. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 11, 2014, 11:04:37 PM
John, it is (< n 2), not (( n 2) again.
Title: Re: Lisp in Basic
Post by: JRS on August 11, 2014, 11:13:07 PM
Thanks!

(http://www.oxygenbasic.org/forum/index.php?action=dlattach;topic=1163.0;attach=3007;image)

This looks like one of his WIFI antennas. (free hot spot extended access device)   :)  How Aurel stays connected.
Title: Re: Lisp in Basic
Post by: JRS on August 12, 2014, 12:02:38 AM
Code: [Select]
F0  F1  F2  F3  F4  F5  F6  F7  F8  F9  F10  F11 F12  F13  F14  F15  F16  F17   F18   F19   F20
0   1   1   2   3   5   8   13  21  34  55   89  144  233  377  610  987  1597  2584  4181  6765

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ time scriba lisp.sb fibonacci.scm
SBLisp - Scheme BASIC Lisp

(define fibonacci (lambda (n)
  (if (< n 2)
      n
      (+ (fibonacci (- n 1))
         (fibonacci (- n 2)))))
)
FIBONACCI
(fibonacci 12)
144
(quit)
Bye!

real 0m0.464s
user 0m0.452s
sys 0m0.008s
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 12, 2014, 12:27:04 AM
Ah yes, that code would count the second sequence rather than the first one. The actual values are the same in the both of them barring 0 which isn't a strict Fibonacci number.

But the 12th number won't be informative because both SB and FBSL would yield zeros similar to O2 or DynC with such a childish task!

Try to be patient for some 5 minutes to calc the 26th one to and see the results in SB and SBLisp that could somehow compare given the differences in our HW (my PC is faster).


Here's its counterpart for your HW reference:

.
Title: Re: Lisp in Basic
Post by: JRS on August 12, 2014, 12:43:39 AM
You have a faster computer than my Toshiba laptop.

Can you run the same for FBSL and SBLisp (fibonacci 14) on your box? (use SBLisp.exe)

Also can you do a prompt to prompt speed test? This is how SB is reporting it's time. There is something to be said for startup and the time it takes to clean up.


Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 12, 2014, 12:56:43 AM
Hold on for a while. I've got something better to offer.

Back.

Now please goto your sources and change your DoLoad as follows:

Code: [Select]
DoLoad:
  ptype = qtype
  pvalue = qvalue
  bsd += 1
  GOSUB Car
  bsd += 1
  GOSUB RregtoPreg
  IF ptype <> symbol THEN
    PRINT "ERROR: Load needs a symbol.\n"
    GOTO HandleError
  END IF
  lispfilename = symbols[pvalue]
  OPTION COMPARE sbCaseInsensitive
  fnpos = INSTR(ibuf, lispfilename)
  IF fnpos THEN lispfilename = MID(ibuf, fnpos, LEN(lispfilename))
  OPTION COMPARE sbCaseSensitive
  lispfilenum = 1
  bsd += 1
  GOSUB LispOpenInputFile
gtc=now
  WHILE NOT EOF(lispfilenum)
    stkcursor = 0
    curenv = globalenv
    bsd += 1
    GOSUB LispRead
    bsd += 1
    GOSUB RregtoPreg
    bsd += 1
    GOSUB LispEval
    bsd += 1
    GOSUB RregtoPreg
    bsd += 1
    GOSUB LispPrint
    PRINTNL
  WEND
print "Done in ",now-gtc," seconds\n"
  bsd += 1
  GOSUB LispCloseFile
  rtype = booleant
  rvalue = TRUE
  bsd -= 1
  RETURN

This will enable you to time the evaluation loop only. It will work for files only but not for interactive evaluation which cannot be timed that simple.

Your resolution will be rough but passable if evaluation takes longer than 10 seconds.

Save your LISP code as a file with (fibonacci 20). Run it to compare it against my reference picture below.

This effectively eliminates all overhead for initializing your arrays with Splita and all other prolog/epilog code. Pure evaluation and garbage collection timed. This is how my measurements are taken too but with the GetTickCount() timer.

.
Title: Re: Lisp in Basic
Post by: JRS on August 12, 2014, 01:23:21 AM
Sweet!

When I get the SDL_gfx interface working it has a sub-second timer.

I'm still interested in a prompt to prompt comparison. I want to see how much time the interpreters are taking to do their jobs. Do you have a Windows console process timer like the Linux time utility?

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 12, 2014, 01:32:36 AM
No, nothing of the sort in Windows' OOTB stock. Perhaps Billy has grown too old and shy to advertise his system timings that easily. :)

I can only throw in a quick FBSL script to shell start the sblisp.exe and time its exit on task completion with GetTickCount(). I'll need about 10 minutes to get the result.
Title: Re: Lisp in Basic
Post by: JRS on August 12, 2014, 01:42:32 AM
I have a free-ware timer (like Linux time) I will send you tomorrow. Bed time, turned into a pumpkin long ago.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 12, 2014, 01:47:38 AM
Here you are.

.
Title: Re: Lisp in Basic
Post by: JRS on August 12, 2014, 01:53:25 AM
Can you do the same for FBSL?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 12, 2014, 02:05:16 AM
Yes, I can. You can goto bed now. When you wake up, you will see the results you're anticipating. But be forewarned (I'm going to use that figure of speech of yours as often as I can): FBSL has lots of ways to improve on this code. It's me that's pulling it to wait till you catch up. I'm a generous man, you know. :D

Good night!



[UPD] Here you are again, and have sweet dreams! :)

.
Title: Re: Lisp in Basic
Post by: JRS on August 12, 2014, 08:31:04 AM
Thanks Mike.

Code: [Select]
Calculate percentage difference
between V1 = 13.797 and V2 = 10.734

( | V1 - V2 | / ((V1 + V2)/2) ) * 100

= ( | 13.797 - 10.734 | / ((13.797 + 10.734)/2) ) * 100
= ( | 3.063 | / (24.531/2) ) * 100
= ( 3.063 / 12.2655 ) * 100
= 0.249725 * 100

= 24.9725% difference

Quote
FBSL has lots of ways to improve on this code. It's me that's pulling it to wait till you catch up. I'm a generous man, you know

We both do. That's what makes this project so much fun. Easy to get there and multiple ways of doing it.



Just got a response back from Arthur and will see if he would like to participate with our new effort. He seems interested in what we are doing.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 12, 2014, 11:57:14 AM
Code: [Select]
Calculate percentage difference
between V1 = 13.797 and V2 = 10.734

( | V1 - V2 | / ((V1 + V2)/2) ) * 100

= ( | 13.797 - 10.734 | / ((13.797 + 10.734)/2) ) * 100
= ( | 3.063 | / (24.531/2) ) * 100
= ( 3.063 / 12.2655 ) * 100
= 0.249725 * 100

= 24.9725% difference

You missed your chance for the moment of true glory. I thought you would do it in BASIC LISP. :P

Where's my time app, please?
Title: Re: Lisp in Basic
Post by: JRS on August 12, 2014, 12:34:29 PM
Quote
You missed your chance for the moment of true glory. I thought you would do it in BASIC LISP

Too lazy. Used an online difference tool.


Quote
Where's my time app, please?


.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 12, 2014, 02:36:51 PM
Quote
ptime-10.zip (23.94 kB - downloaded 1 times.)

Well thanks. Looks like a cheap odd job -- been there with my two GetTickCount() scripts already.

Here comes some "free fizz" from my dinner table to yours. This is an exact same thing built around the Windows high res timer and FBSL's 64-bit long integers a.k.a. QUAD's.

Its current accuracy is 1 microsecond (.001 milliseconds). Potential accuracy is .001 nanoseconds, accurate to the last decimal place displayed.

The picture shows the result of calculating the 24th Fibonacci number in FBLisp (Freestyle BASIC Lisp). Grab your calculator and enjoy yet another shining moment of triumph but don't forget to raise a glass to Peter Verhas. :-*

[EDIT] I must have been absolutely drowsy to have "champagne" misspelt so badly... :)
[EDIT2] OMG I misspelled it again! :-[  So "fizz" be it...

.
Title: Re: Lisp in Basic
Post by: JRS on August 12, 2014, 03:54:27 PM
Here is my run on Ubuntu 64 bit on my Intel® Pentium(R) CPU P6200 @ 2.13GHz × 2 laptop.

Code: [Select]

GC start GC done.
GC start GC done.
46368
(quit)
Bye!

real 1m43.305s
user 1m43.078s
sys 0m0.036s
jrs@laptop:~/sb/sb22/sblisp$

Quote
Grab your calculator and enjoy yet another shining moment of triumph but don't forget to raise a glass to Peter Verhas.

(http://files.allbasic.info/ScriptBasic/toast.png)                (http://files.allbasic.info/ScriptBasic/verhas_peter.jpg)



Thanks for the Windows process timer.

Quote
FBLisp (Freestyle BASIC Lisp)

I like it!

Should get the FreeBASIC group buzzing.
Title: Re: Lisp in Basic
Post by: JRS on August 12, 2014, 07:38:59 PM
I thought I would take a shot at converting GOSUB's to SUB's. Well that didn't work out too well. I noticed that within GOSUB's it does GOTO's to other GOSUB's and other things I don't want to talk about. So, it looks like this is the way it is unless someone wants to unravel this. I understand some of these non-standard program flow decisions were made for efficiency and speed and pushed the limits of QB while writing the Lisp interpreter.

I might have a peek at the source of MIT/GNU Scheme and see how it's designed. (core interpreter)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 12, 2014, 10:24:30 PM
Quote
Here is my run on Ubuntu 64 bit on my Intel® Pentium(R) CPU P6200 @ 2.13GHz × 2 laptop.
Not bad by the looks of it.

Code: [Select]
real 1m43.305s
user 1m43.078s
sys 0m0.036s
I always wanted to have such a thing in Windows but I couldn't figure out how. MS Windows discloses dozens of statistical parameters relevant to ring 3 (user space) but none relevant to ring 1 (kernel space). So yes, here I envy you and my envy is black. :)

Quote
Should get the FreeBASIC group buzzing.
I don't give a damn about FreeBUZZIC's buzzing. Freestyle BASIC Script Language has been around since June 2001. I am in my own right with the letters F, B, S, and L in this very succession. I've yet to see them trying to register the FB abbreviation against Zuckerberg's  FaceBook, hehe...

Quote
I thought I would take a shot at converting GOSUB's to SUB's.
Hmmm, not sure if you've seen my comments on this issue in the last paragraph of my earlier message here (http://www.oxygenbasic.org/forum/index.php?topic=1147.msg10508#msg10508).
Title: Re: Lisp in Basic
Post by: JRS on August 12, 2014, 11:43:10 PM
I'm playing with this at the moment.

Quote
Embeddable Common Lisp (ECL) is a LGPL Common Lisp implementation aimed at producing a small-footprint Lisp system that can be embedded into existing C-based applications. It is able to create stand-alone ELF executables from Common Lisp code and runs on most platforms that support a C compiler.

Because it compiles Common Lisp to C, it also features an FFI system, including support for inline C to be used or generated from Common Lisp. Inline C FFI combined with Common Lisp macros and custom SETF expansions yield a compile-time preprocessor.

http://ecls.sourceforge.net/
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 13, 2014, 12:14:37 AM
Is there any benchmark data in this page (http://ecls.sourceforge.net/pictures/index_json.html) in your browser? I can't see anything there...
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 12:34:35 AM
Looks blank from here as well.

I was able to build ecl from scratch and the test suite which created hundreds of .lsp function libraries. Now I have to figure out how to make all this stuff work.  :o

THIS (http://ecls.sourceforge.net/new-manual/index.html) looks helpful.
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 01:03:39 AM
I know this works as here is the script that built the attach tests directory. It used libcurl to download the file, extracted the source and built this monster with both C and ecl. I'm thinking this has real possibilities.

Code: [Select]
;;; -*- mode: common-lisp; Base: 10 ; Syntax: ANSI-Common-Lisp -*-
;;;
;;; (c) 2011, Juan Jose Garcia-Ripoll
;;;
;;; Set up the test environment.
;;;

(defpackage :ecl-tests
  (:use :cl))

(in-package :ecl-tests)

(setf *load-verbose* nil *load-print* nil)

(defvar *ecl-sources*
  (loop for *default-pathname-defaults* in
'(#p"/home/jrs/ecl/src/" #p"../../" #p"../../src/")
when (probe-file "CHANGELOG")
return *default-pathname-defaults*))

(defvar *test-sources* (merge-pathnames "tests/" *ecl-sources*))

(defvar *here* (merge-pathnames "./"))

(defvar *cache* (merge-pathnames "./cache/" *here*))

(defvar *test-image* (or (ext:getenv "TEST_IMAGE")
#+windows
(namestring (truename #+windows "sys:ecl.exe"))
#-windows
"ecl"))

(defvar *test-image-args*
  (cond ((search "ecl" *test-image*)
'("-norc" "-eval" "(print (ext:getenv \"ECLDIR\"))"
   ;#+windows "-eval" #+windows "(require :cmp)"
   ))
((search "sbcl" *test-image*)
'("--no-userinit" "--no-sysinit"))
(t
'())))

#+ecl
(ext:setenv "ECLDIR" (namestring (truename "SYS:")))

(defvar *test-name* (or (ext:getenv "TEST_NAME") "ecl"))

(defvar *output-directory*
  (merge-pathnames (concatenate 'string "output." *test-name* "/") *here*))

(defvar *quicklisp-sandbox* (merge-pathnames "quicklisp/" *here*))

(defvar *quicklisp-install-file* (merge-pathnames "quicklisp.lsp" *cache*))

(defvar *quicklisp-setup-file* (merge-pathnames "setup.lisp" *quicklisp-sandbox*))

(defvar *regressions-sources* (merge-pathnames "bugs/" *test-sources*))

(defvar *regressions-sandbox* (merge-pathnames "regressions/" *here*))

(defvar *ansi-tests-mirror* "http://ecls.sourceforge.net/ansi-tests.tar.gz")

(defvar *ansi-tests-sandbox* (merge-pathnames "ansi-tests/" *here*))

(defvar *ansi-tests-tarball* "ansi-tests.tar.gz")

(defvar *mop-tests-mirror* "http://ecls.sourceforge.net/mop-features.tar.gz")

(defvar *mop-tests-sandbox* (merge-pathnames "mop-features/" *here*))

(defvar *mop-tests-tarball* "mop-features.tar.gz")

(defvar *fricas-mirror* "http://ecls.sourceforge.net/fricas.tar.gz")

(defvar *fricas-sandbox* (merge-pathnames "fricas/" *here*))

(defvar *fricas-tarball* "fricas.tar.gz")

(defvar *wild-inferiors* (make-pathname :name :wild
:type :wild
:version :wild
:directory '(:relative :wild-inferiors)))

(defvar *cleanup-extensions* '("fasl" "fasb" "c" "h" "obj" "o" "a" "lib" "dll" "dylib" "data"))

(defun lisp-system-directory ()
  (loop with root = (si::get-library-pathname)
with lib-name = (format nil "../lib/ecl-~A/" (lisp-implementation-version))
for base in (list root (merge-pathnames lib-name root))
when (or (probe-file (merge-pathnames "./BUILD-STAMP" base))
(probe-file (merge-pathnames "./LGPL" base)))
do (return base)))

(setf (logical-pathname-translations "SYS")
      (list (list #p"sys:**;*.*"
  (merge-pathnames "**/*.*"
   (lisp-system-directory)))))

(require :cmp)
(require :ecl-curl)
(require :deflate)
(require :ql-minitar)

;;;
;;; PREPARATION OF DIRECTORIES AND FILES
;;;

(defun setup-asdf ()
  (require :asdf)
  (ensure-directories-exist *cache*)
  (setf (symbol-value (read-from-string "asdf::*user-cache*"))
(list *cache* :implementation)))
     

(defun delete-everything (path)
  ;; Recursively run through children
  (labels ((recursive-deletion (path)
             (mapc #'delete-everything
                   (directory (merge-pathnames
                               (make-pathname :name nil
                                              :type nil
                                              :directory '(:relative :wild)
                                              :defaults path)
                               path)))
             ;; Delete files
             (loop for f in (directory (make-pathname :name :wild
                                                      :type :wild
                                                      :defaults path))
                do (delete-file f)
                finally (delete-file path))))
    (and (probe-file path)
         (recursive-deletion path))))

(defun safe-download (url filename)
  (ensure-directories-exist filename)
  (handler-case
      (ecl-curl:download-url-to-file url filename)
    (ecl-curl:download-error (c)
      (format t "~&;;;~%;;; Unable to download quicklisp. Aborting. ~%;;;")
      (ext:quit 1)))
  filename)

(defun download-quicklisp-install ()
  (safe-download "http://beta.quicklisp.org/quicklisp.lisp"
*quicklisp-install-file*))

(defun download-and-setup-quicklisp ()
  (when (probe-file *quicklisp-sandbox*)
    (delete-everything *quicklisp-sandbox*))
  (handler-case
      (progn
(load (download-quicklisp-install))
(let ((function (read-from-string "quicklisp-quickstart:install")))
  (eval (list function :path *quicklisp-sandbox*))))
    (error (c)
      (format t "~&;;;~%;;; Unable to setup quicklisp. Aborting.~%;;;")
      (delete-everything *quicklisp-sandbox*))))

(defun ensure-quicklisp ()
  (unless (find-package "QL")
    (unless (probe-file *quicklisp-sandbox*)
      (setup-asdf)
      (download-and-setup-quicklisp))
    (load *quicklisp-setup-file*))
  t)

(defun copy-directory (orig dest)
  (setf orig (truename orig))
  (print dest)
  (loop for f in (directory (merge-pathnames *wild-inferiors* orig))
     for f2 = (enough-namestring f orig)
     for f3 = (merge-pathnames f2 dest)
     unless (probe-file f3)
     do (ensure-directories-exist f3)
     do (ext:copy-file f f3)))

(defun extract-tarball (filename)
  (format t "~&;;;~%;;; Extracting ~a~%;;;" filename)
  (if (string-equal (pathname-type filename) "gz")
      (let ((temp-filename (ext:mkstemp "fooXXXXXXX")))
(unwind-protect
     (progn
       (deflate:gunzip filename temp-filename)
       (extract-tarball temp-filename))
  (delete-file temp-filename)))
      (ql-minitar:unpack-tarball filename)))

(defun extract-distribution (filename url)
  (let ((distribution (loop for base in (list *cache*
      *here*
      *test-sources*)
for file = (merge-pathnames filename base)
when (probe-file file)
do (return file)
finally (let ((tmp (merge-pathnames filename *cache*)))
   (return (safe-download url tmp))))))
    (extract-tarball distribution)))

(defun ensure-regressions ()
  (unless (probe-file *regressions-sandbox*)
    (copy-directory *regressions-sources* *regressions-sandbox*)))

(defun ensure-ansi-tests ()
  (unless (probe-file *ansi-tests-sandbox*)
    (extract-distribution *ansi-tests-tarball* *ansi-tests-mirror*))
  t)

(defun ensure-mop-tests ()
  (unless (probe-file *mop-tests-sandbox*)
    (extract-distribution *mop-tests-tarball* *mop-tests-mirror*))
  t)

(defun ensure-fricas ()
  (unless (probe-file *fricas-sandbox*)
    (extract-distribution *fricas-tarball* *fricas-url*)))

(defun ensure-maxima ()
  (unless (probe-file *fricas-sandbox*)
    (extract-distribution *fricas-tarball* *fricas-url*)))

(defun cleanup-directory (path)
  (loop for i in (directory (merge-pathnames *wild-inferiors*
     path))
     when (member (pathname-type i) *cleanup-extensions* :test #'string-equal)
     do (delete-file i)))

;;;
;;; RUNNING TESTS
;;;

(defun run-ansi-tests (&optional (output (merge-pathnames "ansi.log"
  *output-directory*)))
  (ensure-ansi-tests)
  ;; Cleanup stray files
  (cleanup-directory *ansi-tests-sandbox*)
  (delete-everything (merge-pathnames "scratch/" *ansi-tests-sandbox*))
  ;; Run with given image
  (ensure-directories-exist output)
  (let* ((input (merge-pathnames "doit.lsp" *ansi-tests-sandbox*))
(tmp (merge-pathnames "ecl-tmp-doit.lsp" *ansi-tests-sandbox*)))
    (with-open-file (s tmp :direction :output
       :if-exists :supersede
       :if-does-not-exist :create)
      (format s "(require :cmp)
#+ecl(setf c::*suppress-compiler-messages* '(or c::compiler-note c::style-warning))
(pprint (ext:getcwd))
(load ~S)
#+ecl(quit)"
      (namestring input)))
    (unwind-protect
(progn
  (ext:chdir *ansi-tests-sandbox*)
  (ext:run-program *test-image*
   *test-image-args*
   :input tmp
   :output output
   :error :output
   :wait t))
      (when (probe-file tmp)
(ignore-errors (delete-file tmp)))
      (ext:chdir *here*))))

(defun run-regressions-tests (&optional (output (merge-pathnames "regressions.log"
*output-directory*)))
  (ensure-regressions)
  ;; Cleanup stray files
  (cleanup-directory *regressions-sandbox*)
  ;; Run with given image
  (ensure-directories-exist output)
  (unwind-protect
       (progn
(ext:chdir *regressions-sandbox*)
(ext:run-program *test-image*
  *test-image-args*
  :input (merge-pathnames "doit.lsp" *regressions-sandbox*)
  :output output
  :error :output))
    (ext:chdir *here*)))

(defun run-mop-tests (&optional (output (merge-pathnames "mop-features.log"
*output-directory*)))
  (ensure-mop-tests)
  ;; Cleanup stray files
  (cleanup-directory *mop-tests-sandbox*)
  ;; Create the script we are going to run
  (let ((mop-script (merge-pathnames "./run-mop-tests.lisp" *mop-tests-sandbox*)))
    (with-open-file (s mop-script :direction :output
       :if-exists :supersede
       :if-does-not-exist :create)
      (pprint '(progn
(require :asdf)
(load "lw-compat-package")
(load "lw-compat")
(load "mop-features-packages.lisp")
(load "mop-feature-tests.lisp")
(handler-case
    (progn
      (funcall (read-from-string "mop-feature-tests::run-feature-tests"))
      (format t "~%~%~%MOP-FEATURE-TESTS: OK"))
  (error (error)
    (format t "~%~%~%MOP-FEATURE-TESTS: Failed"))))
      s))
    ;; Run with given image
    (ensure-directories-exist output)
    (unwind-protect
(progn
   (ext:chdir *mop-tests-sandbox*)
   (ext:run-program *test-image*
    *test-image-args*
    :input mop-script
    :output output
    :error :output))
      (ext:chdir *here*))))


(defvar *quicklisp-library-list*
  '(trivial-features
    alexandria
    babel
    cffi
    cl-ppcre
    cl-unicode
    iterate
    trivial-gray-streams
    trivial-garbage
    flexi-streams
    lift
    metabang-bind
    swank
    stefil
    sqlite
    chunga
    cl+ssl
    cl-base64
    cl-fad
    cl-python
    md5
    rfc2388
    trivial-backtrace
    trivial-gray-streams
    usocket
    hunchentoot))

(defconstant +quicklisp-build-template+ "
(require 'asdf)
(setf (symbol-value (read-from-string \"asdf::*user-cache*\"))
      (list ~s :implementation))
(load ~s)
(ql:use-only-quicklisp-systems)
(handler-case
  (progn
    (ql:quickload ~s)
    (princ \"ECL-BUILD-OK\"))
  (serious-condition (c) (princ c)))
#+ecl
(ext:quit)
#+sbcl
(sb-ext:quit)
")

(defconstant +quicklisp-test-template+ "
(require 'asdf)
(setf (symbol-value (read-from-string \"asdf::*user-cache*\"))
      (list ~s :implementation))
(load ~s)
(ql:use-only-quicklisp-systems)
(handler-case
  (progn
    (ql:quickload ~s)
    (princ \"ECL-BUILD-OK\")
    (asdf:oos 'asdf:test-op ~:*~s)
    (princ \"ECL-TEST-OK\"))
  (serious-condition (c) (princ c)))
#+ecl
(ext:quit)
#+sbcl
(sb-ext:quit)
")

(defun run-quicklisp-tests (&optional (output (merge-pathnames "quicklisp.log"
       *output-directory*)))
  (mapcar #'delete-everything (directory (merge-pathnames "*/" *cache*)))
  (let ((quicklisp-logs (merge-pathnames "quicklisp.logs/" *output-directory*)))
    (labels ((build-or-test-job (name suffix template)
       (let* ((name (string-downcase name))
      (log-name (concatenate 'string name suffix))
      (build-log (ensure-directories-exist
  (merge-pathnames log-name quicklisp-logs))))
(multiple-value-bind (stream status process)
     (ext:run-program *test-image*
      *test-image-args*
      :input :stream
      :output build-log
      :error :output
      :wait nil)
   (unwind-protect
(progn
  (format stream template
  (namestring *cache*)
  (namestring *quicklisp-setup-file*)
  name)
  (format t template
  (namestring *cache*)
  (namestring *quicklisp-setup-file*)
  name)
  (force-output stream))
     (close stream)
     (ext:external-process-wait process t)
     ))))
     (build-job (name)
       (build-or-test-job name "-build.log" +quicklisp-build-template+))
     (test-job (name)
       (build-or-test-job name "-test.log" +quicklisp-test-template+)))
      (mapc #'build-job *quicklisp-library-list*)
      (mapc #'test-job *quicklisp-library-list*))))

Loading a library from ecl lisp.

Code: [Select]
(load-foreign-library #p"/usr/lib/libmysqlclient.so"
                      :module "mysql"
                     :supporting-libraries '("c"))
=> T


.
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 08:37:51 AM
I still have a lot of reading to do but what I'm seeing so far is ECL (Embedded Common Lisp) allows you to create linked libraries and standalone binaries in Common Lisp as well as an API that allows Lisp functionality from the hosting language as function calls. Has anyone else looked at this?

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 13, 2014, 09:46:44 AM
Supposedly "anyone else" is me.

All this embedding, compilation, linking, modularizing, etc. stuff is OK for Linux but KO for Windows and Mac OS X. We do not have a system compiler and gigs of object libraries to match. Windows and Mac users are white- and blue-collar workers, intellectuals, and artists but not red eyed terminal happy coding geeks nor freaks.

Apart from that, this ECL thingy looks like an exact match to SB's own design and workflow in its Linux hypostasis. The other platforms may be satisfied with a standalone SB interpreter and a matching LISP bytecode interpreter DLL/DYLIB plug-in.
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 09:53:03 AM
Quote
Apart from that, this ECL thingy looks like an exact match to SB's own design and workflow in its Linux hypostasis. The other platforms may be satisfied with a standalone SB interpreter and its matching LISP bytecode interpreter plug-in.

I was wondering what your take was on this. It's seems like Lisp Christmas for Linux and tailored for environments like SB. I hope that FBSL not being ported to Linux yet doesn't keep you away from experimenting with tools on that platform.

 
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 13, 2014, 10:18:35 AM
I hope that FBSL not being ported to Linux yet doesn't keep you away from experimenting with tools on that platform.

No, it doesn't. You have just reported that my fixes to your initial submission of SBLisp are working perfectly well under your 64-bit Ubuntu as well as my 32-bit Windows.

From an outsider's perspective, ECL looks like a project of quality and ambition comparable with SB. OTOH SBLisp doesn't and it will never be anything but a toy as long as it stays written in SB. Go ahead with ECL, John, it would be much more reasonable to do than try and rewrite SBLisp in CBASIC. That is if you are seriously planning to enrich SB with another language similar to how O2 is enriched with assembly, and FBSL, with DynC and DynAsm.
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 10:38:45 AM
It would be great if you can find the time to mentor me along with the ECL effort on Linux. When I created the SB SDL GFX extension module in C BASIC, it only took a few tweaks to use the same C BASIC library with BaCon. I guess my point is that your efforts wouldn't be SB specific but a common language binding effort of how to embed Lisp with C. We used SB as a testing ground for proof of concept. It's just easy to use.

I agree that SBLisp is a toy and a fun way to learn Lisp without a lot of pain. I can't thank you enough for all the help and code bringing that to a reality. I enjoy working with you and hope that doesn't stop with the common effort SBLisp, FBLisp and OxyLisp project.



Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 13, 2014, 01:48:32 PM
We used SB as a testing ground for proof of concept. It's just easy to use.
Naturally enough, FBSL is the easiest for me. Oxygen stays the toughest. The OxyLISP evaluator still fails me, or rather I'm failing as an O2 user.

Quote
I can't thank you enough for all the help and code bringing that to a reality.
Thank you for the kind words. Actually I'm a steppen wolf when coding but this thread did bring a lot of life and entertainment to my LISP dev experience.

As for the rest of it, I'm feeling obliged to bring OxyLISP to completion. I'll probably spawn another topic where it's going to be the subject matter, its SB and FBSL siblings staying in the background as reference models.

Then what? Frankly, I don't know yet. Probably, back to FBSL v3.5 RC3 and Final.
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 02:59:53 PM
I'm happy where SBLisp is currently. If someone finds a bug, I'll be sure to look into it. (Translation: Mike, we got a bug in ...)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 13, 2014, 03:05:30 PM
Where?!  :o
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 03:33:59 PM
Here is where I'm at currently. (Hint: GCL GNU Common-Lisp)

Code: [Select]
(defun fibonacci (n)
  (if (< n 3)
      1
      (+ (fibonacci (- n 1)) (fibonacci (- n 2))) ) )

(loop for i from 1 to 24
   do (format t "~D, " (fibonacci i))
   finally (format t "...~%") )

jrs@laptop:~/gcl$ time gcl -batch -load /home/jrs/gcl/fibonacci.lsp
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, ...

real   0m0.174s
user   0m0.148s
sys   0m0.020s
jrs@laptop:~/gcl$
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 13, 2014, 03:52:49 PM
Phew!

Easy John, I shouldn't be having blood pressure jumps like that at 3 in the morning... :D

Why should it be called a "bug"? This is a totally alien syntax and this functionality is missing from the original Lisp-in-Basic. That's like expecting raw C code to run in the SB interpreter.

<suspicion> Or are you implying you've gone that far in putting your SBLisp syntax on the GCL rails?! :o </suspicion>
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 03:59:28 PM
Quote
<suspicion> Or are you implying you've gone that far in putting your SBLisp on the GCL rails?! :o </suspicion>

Nope. Just tried the GCL interpreter to see what it will do on the track.  ;D

Can't imagine what it will be like when compiled to C.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 13, 2014, 04:09:17 PM
You mean, speed-wise?

BTW all this can be rewritten in the existing SBLisp. I'm too tired tonight (it's been my youngest son's 16th birthday party today -- your time). Adulthood and stuff. Temptations and responsibilities. But I can do it for you tomorrow. Not very difficult actually except for tricky print formating. Remember, we can't print a space yet. :)
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 04:23:31 PM
Quote
You mean, speed-wise?

Yes. Are you saying the fibonacci.lsp script I found and posted for GNU Common Lisp is more efficient and will produce better numbers under our current SBLisp/FBLisp versions?

I think we should add a DEBUG flag and only show GC start GC finish and other annoying print messages only when enabled.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 13, 2014, 04:40:33 PM
Of course not. The execution time will be on the order of 10 seconds or more. But it will print its intermediate results separated with a comma and it will even add the trailing ellipsis. There will be no spaces though.

You can add command line options easily. Let your initial command line evaluator do, say, a INSTR(COMMAND(), " -d ") or INSTR(COMMAND(), " /d ") search for trailing options, adjust the flags accordingly, and chop the command line with a matching RTRIM(LEFT(COMMAND(),INSTR(...))) at the first option found to let the remaining command line serve as the file name to load and execute. Voila.

[EDIT] FBSL features a Command(N) function and a matching CommandCount() function with all the space delimited command line elements pre-parsed and ready for iteration.
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 04:49:56 PM
Much easier than that.

Code: [Select]
cmd = COMMAND()

SPLIT cmd BY " " TO DEBUG, filename

scriba lisp.sb -D fibonacci.scm

You would need some IF logic to see if there are more than 1 (filename) argument on the command line. The point was SPLIT will do the job.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 13, 2014, 04:59:44 PM
FBSL has also a special value Command(-1) that will return the raw command line, and an equivalent Split() function to parse a string into an array of tokens by any separator(s). We can use those for command line parsing thus making the code as unified as possible. :)

OK John, I guess it's time for me to go. (boose has taken its toll :) )

See you tomorrow.
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 06:03:25 PM
I have pushed the change to Bitbucket. Here is the main part of the change. (3 other one line changes done as well)

This version allows any order of the two options, extra spaces and lower case on the -D. Another SB feature that makes this work is that SPLITA / SPLIT only uses the first occurrence of the defined delimiter in case there is a string of them in a row.

Code: [Select]
cmdln = COMMAND()

SPLITA TRIM(cmdln) BY " " TO cmdlnargs
dbgflg = FALSE
FOR x = 0 TO UBOUND(cmdlnargs)
  IF TRIM(UCASE(cmdlnargs[x])) = "-D" THEN
    dbgflg = TRUE
  ELSE IF TRIM(cmdlnargs[x]) <> undef THEN
    cmdflg = TRUE
    cmdlnfn = TRIM(cmdlnargs[x])
  ELSE
    cmdflg = FALSE
  END IF
NEXT
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 10:07:02 PM
Here is my first compile effort with ECL.

Compile
Code: [Select]
(compile-file "fibonacci.lsp" :system-p t)
(c:build-program "fibonacci" :lisp-files '("fibonacci.o"))

jrs@laptop:~/gcl$ time ./fibonacci
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, ...

real   0m0.166s
user   0m0.140s
sys   0m0.020s
jrs@laptop:~/gcl$ ls -l fibonacci
-rwxrwxr-x 1 jrs jrs 43860 Aug 13 23:02 fibonacci
jrs@laptop:~/gcl$
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 10:41:02 PM
Here we have a C recursive Fibonacci series.

Code: [Select]
#include<stdio.h>

int Fibonacci(int);

int main()
{
int n = 24, i = 0, c;
printf("Fibonacci series\n");
for ( c = 1 ; c <= n + 1 ; c++ )
{
printf("%d\n", Fibonacci(i));
i++;
}
return 0;
}

int Fibonacci(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );
}

jrs@laptop:~/ecl/examples/jrs$ time ./fibonacci
Fibonacci series
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368

real   0m0.004s
user   0m0.000s
sys   0m0.000s
jrs@laptop:~/ecl/examples/jrs$
 
Title: Re: Lisp in Basic
Post by: JRS on August 13, 2014, 11:02:45 PM
It seems no matter where I go, I always end up back where I started.

Code: [Select]
FUNCTION Fibonacci(n)
  IF n = 0 THEN
    Fibonacci = 0
  ELSE IF n = 1 THEN
    Fibonacci = 1
  ELSE
    Fibonacci = Fibonacci(n - 1) + Fibonacci(n - 2)
  END IF
END FUNCTION

PRINT "Fibonacci series\n"
FOR x = 1 TO 24
  PRINT Fibonacci(x),"\n"
NEXT

jrs@laptop:~/sb/sb22/sblisp$ time scriba fibonacci.sb
Fibonacci series
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368

real   0m0.430s
user   0m0.428s
sys   0m0.004s
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 14, 2014, 12:31:58 AM
Hi,

It looks as follows here, exe load and bytecode/JIT compilation overhead included: (therefore not very informative for such a low number of iterations, especially in DynC)

.
Title: Re: Lisp in Basic
Post by: JRS on August 14, 2014, 06:47:54 AM
Thanks Mike for the post.

I had a lot of fun working with you and getting Arthur's Lisp interpreter going in SB. I'm willing to keep improving the SBLisp version as time permits as a educational tool. Learning Lisp by building an interpreter isn't a bad way to get there. (just like new BASIC programmers learning the language, creating a new variation is a prerequisite)

SB works for me and I need to get back to that effort. (SB 2.2 release)

Title: Re: Lisp in Basic -- a good survey
Post by: RobbeK on August 14, 2014, 09:39:12 AM
Hi all,  John , Mike :

http://common-lisp.net/~dlw/LispSurvey.html

best Rob
Title: Re: Lisp in Basic
Post by: JRS on August 14, 2014, 09:49:11 AM
Thanks Rob!

Great resource.
Title: Re: Lisp in Basic
Post by: JRS on August 14, 2014, 05:48:44 PM
Mike,

Any ideas how we might add support for printing spaces and other non-standard characters?

I think this would be the next thing if you have any interest in improving on our version of LISP in BASIC.

John
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 14, 2014, 09:46:41 PM
Hi John,

Assuming we do not want to change the current behavior of either XBLisp '-literals, or its (print) command (which I don't like at all BTW), or its (eval) rules, we may safely overwrite the existing GetSymbol: with the following code:

Code: [Select]
GetSymbol:
  total = 0
  opos = ipos
  smb = 1
  slength = FALSE
  GetHashNumLoop:
  IF ipos = LEN(ibuf) + 1 THEN GOTO CheckExistance
  curchar = UCASE(MID(ibuf, ipos, 1))
  IF slength = TRUE THEN
    IF curchar = "\"" THEN
      ipos += 1
      GOTO CheckExistance
    ELSE
      GOTO DoStrLiteral
    END IF
  ELSE
    IF curchar = "\"" THEN
      ipos += 1
      opos = ipos
      slength = TRUE
    END IF
  END IF
  IF INSTR(" ()'", curchar) THEN GOTO CheckExistance
DoStrLiteral:
  temp = ASC(curchar) * smb + total
  total = temp - (INT(temp / maxsymboltablesize) * maxsymboltablesize)
  temp = smb * 256
  smb = temp - (INT(temp / maxsymboltablesize) * maxsymboltablesize)
  ipos += 1
  GOTO GetHashNumLoop
  CheckExistance:
  IF symbols[total] = "" THEN GOTO PutInTable
  temp = symbols[total]
  IF temp = UCASE(MID(ibuf, opos, ipos - opos + slength)) THEN
    ctype = symbol
    cvalue = total
    bsd -= 1
    RETURN
  END IF
  temp = total * total
  total = temp - (INT(temp / maxsymboltablesize) * maxsymboltablesize)
  GOTO CheckExistance
  PutInTable:
  IF slotsfilled = maxsymboltablesize THEN
    PRINT "ERROR: Symbol table full.\n"
    END
  END IF
  symbols[total] = UCASE(MID(ibuf, opos, ipos - opos + slength))
  ctype = symbol
  cvalue = total
  slotsfilled += 1
  bsd -= 1
  RETURN

The only difference between FBSL and SB/O2 will be the sign of variable slength in the two MID() statements because FBSL has TRUE = 1 while SB/O2 have TRUE = -1. The above code is valid for SB and O2.

Long string literals will be stored in the hash table together with all other literals as SYMBOLs and they will behave in the exact same way as their single-word counterparts. You can use whatever escapes SB's PRINT would normally understand in between the double quotes.

Please see also the attached picture.



.
Title: Re: Lisp in Basic
Post by: JRS on August 14, 2014, 10:09:25 PM
Sweet!

I should have a treat for you as well soon.

Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 12:22:10 AM
I restructured SBLisp to look and work like a standard BASIC program without the (legal but hard to follow) shortcuts. GetSymbol is now a SUB so I slightly modified your new routine. It just hangs SBLisp and the old converted one works fine. I can't see the difference between them.  :-[

Bitbucket has been updated with the new version of the code. PLEASE TEST !!!

Mike's Version
Code: [Select]
SUB GetSymbol
  total = 0
  opos = ipos
  smb = 1
  slength = FALSE
  GetHashNumLoop:
  IF ipos = LEN(ibuf) + 1 THEN GOTO CheckExistance
  curchar = UCASE(MID(ibuf, ipos, 1))
  IF slength = TRUE THEN
    IF curchar = "\"" THEN
      ipos += 1
      GOTO CheckExistance
    ELSE
      GOTO DoStrLiteral
    END IF
  ELSE
    IF curchar = "\"" THEN
      ipos += 1
      opos = ipos
      slength = TRUE
    END IF
  END IF
  IF INSTR(" ()'", curchar) THEN GOTO CheckExistance
DoStrLiteral:
  temp = ASC(curchar) * smb + total
  total = temp - (INT(temp / maxsymboltablesize) * maxsymboltablesize)
  temp = smb * 256
  smb = temp - (INT(temp / maxsymboltablesize) * maxsymboltablesize)
  ipos += 1
  GOTO GetHashNumLoop
  CheckExistance:
  IF symbols[total] = "" THEN GOTO PutInTable
  temp = symbols[total]
  IF temp = UCASE(MID(ibuf, opos, ipos - opos + slength)) THEN
    ctype = symbol
    cvalue = total
    bsd -= 1
    EXIT SUB
  END IF
  temp = total * total
  total = temp - (INT(temp / maxsymboltablesize) * maxsymboltablesize)
  GOTO CheckExistance
  PutInTable:
  IF slotsfilled = maxsymboltablesize THEN
    PRINT "ERROR: Symbol table full.\n"
    END
  END IF
  symbols[total] = UCASE(MID(ibuf, opos, ipos - opos + slength))
  ctype = symbol
  cvalue = total
  slotsfilled += 1
  bsd -= 1
END SUB

Here is Fibonacci 24 with the new version.

jrs@laptop:~/sb/sb22/sblisp$ time scriba lisp.sb fibonacci.scm
SBLisp - Scheme BASIC Lisp

(define fibonacci (lambda (n)
  (if (< n 2)
      n
      (+ (fibonacci (- n 1))
         (fibonacci (- n 2)))))
)
FIBONACCI
(fibonacci 24)
46368
(quit)
Bye!

real   1m47.182s
user   1m47.043s
sys   0m0.048s
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: RobbeK on August 15, 2014, 01:12:28 AM
Hi,

At this moment  next is also getting tempting   i.o.    (construct lisp basic (john mike))   ->   (construct basic lisp (rob))

..  there are modules in lisp setting up the infix notation and the rest is a question of writing macro's   , the whole thiing can be compiled into native code or bytecode  (those Lisps run on almost any system ).
But keeping the words of (one of Mike's mentors ?) in mind :    "   try ? no try ...   do or not do "   I have to consider things first .

best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 01:16:33 AM
Code: [Select]
SUB GetSymbol
  total = 0
  opos = ipos
  smb = 1
  slength = FALSE
GetHashNumLoop:
  IF ipos = LEN(ibuf) + 1 THEN GOTO CheckExistance
  curchar = UCASE(MID(ibuf, ipos, 1))
  IF slength = TRUE THEN
    IF curchar = "\"" THEN
      ipos += 1
      GOTO CheckExistance
    ELSE
      GOTO DoStrLiteral
    END IF
  ELSE
    IF curchar = "\"" THEN
      ipos += 1
      opos = ipos
      slength = TRUE
    END IF
  END IF
  IF INSTR(" ()'", curchar) THEN GOTO CheckExistance
DoStrLiteral:
  temp = ASC(curchar) * smb + total
  total = temp - (INT(temp / maxsymboltablesize) * maxsymboltablesize)
  temp = smb * 256
  smb = temp - (INT(temp / maxsymboltablesize) * maxsymboltablesize)
  ipos += 1
  GOTO GetHashNumLoop
CheckExistance:
  IF symbols[total] = CHR(0) THEN GOTO PutInTable
  temp = symbols[total]
  IF temp = UCASE(MID(ibuf, opos, ipos - opos + slength)) THEN
    ctype = symbol
    cvalue = total
    bsd -= 1
    EXIT SUB
  END IF
  temp = total * total
  total = temp - (INT(temp / maxsymboltablesize) * maxsymboltablesize)
  GOTO CheckExistance
PutInTable:
  IF slotsfilled = maxsymboltablesize THEN
    PRINT "ERROR: Symbol table full.\n"
    END
  END IF
  symbols[total] = UCASE(MID(ibuf, opos, ipos - opos + slength))
  ctype = symbol
  cvalue = total
  slotsfilled += 1
  bsd -= 1
END SUB

Quote
Here is Fibonacci 24 with the new version.

Is that good or bad?

.
Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 01:24:09 AM
Quote
Is that good or bad?

No change. That's good.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 01:29:30 AM
BTW symbols[total] = "" in this Sub/former GoSub doesn't work any more like it used to before. Only the new symbols[total] = CHR(0) works otherwise SBLisp hangs.

Have you changed the way ibuf is chopped/CHOMPed/[R | L]TRIMmed in GetLine or whadayacallit?


P.S. Hmmmm no you haven't... Inscrutable are the ways of the Lord!  Anyway it seems like working now, so be it. The Principle of Lazy Coding teaches us: do not touch the code that works.
Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 01:43:44 AM
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
SBLisp - Scheme BASIC Lisp

0]' "Thanks Mike for the fix!"
THANKS MIKE FOR THE FIX!
0](quit)
Bye!
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 01:46:18 AM
Bye-bye! :D

See you later,
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 01:48:55 AM
Hi Rob,

I'm awfully sorry but I didn't quite get your message. :-[ Can you please try and put it for me in some other words?

Does that mean that you are ready to participate? :)
Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 01:50:35 AM
Thanks for the space and allowing me to express myself with non-standard character(s).  :D

Good-Night (morning)
Title: Re: Lisp in Basic
Post by: RobbeK on August 15, 2014, 04:19:13 AM
The idea was writing a kind of ~Basic~ in CL  ::)

PS , there is one CL that is always forgotten, probably caused by the lack of documentation -- nevertheless it is maintained well ..  it's ManKai Common Lisp , I think it comes with ASDF onboard.   (benchmarks seem around those of GCL  -- see attachment , including those for CLISP (the green one)   -- bytecode + GNU Lightning JIT.

and another interesting reading ...
http://www.flownet.com/ron/papers/lisp-java.pdf
"Erann Gat (Ron Garret) of NASA's Jet Propulsion Lab. A short study showing Lisp programs were shorter, took less time to develop, and actually ran faster than the same programming tasks in C++, let alone Java:"

(ps : the NAVEX code for the Space Shuttle is written in Lisp too )

best Rob
 

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 05:01:43 AM
!!! COOL !!! TERRIFIC !!!

Rob, you're a genius! It hasn't been done ever before to the best of my knowledge.

IMO you should choose the fastest LISP available with the native code compilation capability.

Hehe man isn't that gonna be a real something! A BASIC with 1000-digit integers both sides of 0 and native compilation into the bargain...

You'll be carved in stone next to the presidents in Mount Rushmore! ;D

(http://topics.info.com/image/400x200/from_what_type_of_stone_was_mount_rushmore_national_monument_carved.jpg)
Title: Re: Lisp in Basic
Post by: jack on August 15, 2014, 06:36:17 AM
here's very primitive basic interpreter in lisp http://informatimago.com/develop/lisp/com/informatimago/small-cl-pgms/basic/
Title: Re: Lisp in Basic
Post by: RobbeK on August 15, 2014, 07:08:14 AM
@ Jack   --  perfect starter !!!  thank you ( i only found a pascal written in Scheme to cheat a little ).

@ Mike  -- you can turn off those bignum's in CL  to get faster native code , and if you wish you can write non-variadic and "typed" code too -- no problem
Attached something special --  it's my Fibonacci definition -- , the assignment of the variables is done in parallel here (Lisp has such things   p.e.  "let" is parallel assigment ;   "let*" is serial assignment   --  here it is about psetf  (or psetq)  this means something as :
a = 4
b = 5

& then a=b : b=a  resulting in

a = 5
b = 4   8)     --  cool not ,    the basic beginners mistake corrected !!!

best Rob



.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 07:16:15 AM
What's the size of gazonk0.o file?

Faster?! Faster than 20 msec for the 10000th Fibonacci number?!! What for?!!! :D
Title: Re: Lisp in Basic
Post by: jack on August 15, 2014, 07:31:58 AM
RobbeK,
is this the correct behavior of your fib function?
Quote
> (fib 3)
2
> (fib 3)
8
> (fib 3)
34
> (fib 3)
144
> (fib 3)
610
Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 08:03:18 AM
Mike,

What does this new SBLisp structure do to our LISP in BASIC common effort ? Are you still sticking with the QB format?

Code: [Select]
IF INSTR(" ()'", curchar) THEN GOTO CheckExistance

Shouldn't this be ...

Code: [Select]
IF INSTR(" ()'", curchar) <> undef THEN GOTO CheckExistance

John
Title: Re: Lisp in Basic
Post by: RobbeK on August 15, 2014, 08:08:30 AM
OOps , Jack ...

seems I hit an iceberg -- it starts accumulating things (?)  -- what's happening here ... ???

attached, a solution  --  does things parallel too, and it's even faster


(strange what happened here with the psetq / psetf )

best Rob

.
Title: Re: Lisp in Basic
Post by: jack on August 15, 2014, 08:55:41 AM
thank you RobbeK :)
Title: Re: Lisp in Basic
Post by: RobbeK on August 15, 2014, 09:09:55 AM
Mike ,   gazonk0.o  is  1308 bytes


best, Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 04:09:32 PM
What does this new SBLisp structure do to our LISP in BASIC common effort ? Are you still sticking with the QB format?
We absolutely must find a way to formulate the remaining GoSub's as Subs even if it leads to duplicating some pieces of relevant GoTo code. Otherwise it will be impossible to use this code for either DynC or CBASIC that don't support labels which are accessible with both a call (=GoSub) and a jump (=GoTo) at the same time.

Quote
Code: [Select]
IF INSTR(" ()'", curchar) THEN GOTO CheckExistance
Shouldn't this be ...

Code: [Select]
IF INSTR(" ()'", curchar) <> undef THEN GOTO CheckExistance
Their SB logic in both cases evaluates to IF TRUE THEN GOTO (I tested and confirmed it) but if the second variant looks more natural to you, you can safely use it in your SBLisp code. I can read both notations equally fast and it doesn't distract or annoy me.
Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 04:22:30 PM
Quote
Their SB logic in both cases evaluates to IF TRUE THEN GOTO ...

I have had this bite me in the ass more times then I'm willing to say. We have already run into this in SBLisp where an undef result compare was needed. I have learned to keep an open eye for SB internal function undefs. The REF array swap you discovered was a great find!

Code: [Select]
GetNumber:
  total = VAL(curchar)
  BuildNumberLoop:
  IF decimalp THEN decimal += 1
  ipos += 1
  IF ipos > LEN(ibuf) THEN GOTO MakeNumber
  curchar = MID(ibuf, ipos, 1)
  IF curchar = "." THEN
    IF NOT decimalp THEN
      decimalp = TRUE
      GOTO BuildNumberLoop
    ELSE
      ipos = opos
      GetSymbol()
      RETURN
    END IF
  END IF
  IF curchar >= "0" AND curchar <= "9" THEN
    total = total * 10 + VAL(curchar)
    GOTO BuildNumberLoop
  END IF
  IF INSTR("()'", curchar) <> undef OR curchar <= " " THEN
  GOSUB MakeNumber
  RETURN
  END IF 
  ipos = opos
  GetSymbol()
  RETURN


Quote
We absolutely must find a way to formulate the remaining GoSub's as Subs even if it leads to duplicating some pieces of relevant GoTo code. Otherwise it will be impossible to use this code for either DynC or CBASIC that don't support labels which are accessible with both a call (=GoSub) and a jump (=GoTo) at the same time.

I agree but this was a good first step. Maybe making larger SUB/FUNCTION that encapsulates more common functionality.

Recommendations or code is always appreciated. I hope to get Arthur back on-board with this. We have exchanged a couple e-mails.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 04:25:05 PM
Mike ,   gazonk0.o  is  1308 bytes
Thanks Rob. With such a size, it looks like a program launcher only rather than the CL main code file.

OOps , Jack ...
seems I hit an iceberg
Yes Rob, your timing for the 10000th fibonumber also seems absolutely impossible to me. It takes 222 seconds for DynC to find the 52nd one and it would take years to find the 60th. 20 milliseconds are simply unrealistic.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 04:37:19 PM
We have already run into this in SBLisp where an undef result compare was needed.
Code: [Select]
IF INSTR("()'", curchar) <> undef OR curchar <= " " THEN
This is a trickier case with intermediate logical evaluation involved due to OR. Similar OR evaluations were also buggy in Charles' O2 until very recently when Ed's Toy interpreter started to function due to Charles having fixed up this very bug.

FBSL cracks all such logic very easily but I can maintain your style throughout the code for the sake of unification if you want me to. Absolutely NP with it here.

Quote
I agree but this was a good first step.
Sure and thanks for taking it. :)

Quote
I hope to get Arthur back on-board with this. We have exchanged a couple e-mails.
Was it Arthur who pointed you to ECL?
Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 04:56:19 PM
Quote
Was it Arthur who pointed you to ECL?

No. Google.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 05:19:03 PM
Quote
Maybe making larger SUB/FUNCTION that encapsulates more common functionality.
Do you think you could do it for the project? The proc size and code duplication would be no problem at this stage. Then it will be easier to spot the duplicates and reduce them to yet finer common Subs until eliminated entirely. There's almost no difference in the overhead of a jump or call in a variant-based interpreter so it shouldn't affect its execution speed noticeably. At the same time, it will enable us to later turn the Sub calls from the existing IF tree into a call table (computed gotos) for DynC, C, and O2. It could improve the speed of their machine-coded interpretation.
Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 06:36:05 PM
Quote
Do you think you could do it for the project?

I could try. It took me three times of abandoning this current effort before getting to where it is now. I was on the edge of saying this is a waste of time.

It would be nice to have a GOSUB diagram of what calls what. Is that something you could generate quickly?

I would like to see a real Scheme script run in S|FBLisp that actually does something useful. This would at least tell us if the syntax of the language works.
Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 09:38:08 PM
I thought I would kill two birds using Dave's IDE/Debugger to solve this GOSUB to SUB/FUNCTION phase. I discover a problem with it creating an exception error. Sent an e-mail off to Dave. Here is a helpful feature of the IDE I like. (see attached) All you have to do is select the text and it shows the instance count. (highlighting all occurrences)



.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 09:43:08 PM
... what calls what. Is that something you could generate quickly?
Hehe it would be a trivial task for a machine code executable and almost any decent disassembler out there would provide you with one in a few seconds. But it's impossible to have for an indie interpreter written in yet another interpreter. It would require a separate program and thorouh knowledge of the structure of both languages. :)

Quote
I would like to see a real Scheme script run in S|FBLisp that actually does something useful. This would at least tell us if the syntax of the language works.
There are hardly many useful app tasks that would fit into the Procrustean bed of XFLisp's current vocabulary. But looking for one might really trigger its development. (I'm still not able to make OxyLISP's evaluator work with anything other than numbers... :-\ )

P.S. I was talking about graphical or at least tabulated cross-references - usual practice in disassemblers and asm activity in general.
Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 10:04:56 PM
Quote
But it's impossible to have for an indie interpreter written in yet another interpreter. It would require a separate program and thorouh knowledge of the structure of both languages.

Using the SB IDE/Debugger will give me what I'm after.

If you can concentrate on XBLisp scripts that show what this thing is capable of, that would VERY helpful. Here is a start.  ;)

Code: [Select]
0](eq? (list 'a 'b) (list 'a 'b))
()
0](equal? (list 'a 'b) (list 'a 'b))
T
0](+ 4 (* 5 6))
34
0](define x 6)
X
0](+ (* 5 x x) (* 4 x) 3)
207
0](/ 21 5)
4.200000
Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 10:27:54 PM
This is how I'm dealing with GOSUBs that don't call anything other than the HandleError: routine.

Code: [Select]
FUNCTION PushStack
  stacktype[stkcursor] = ptype
  stackvalue[stkcursor] = pvalue
  stkcursor += 1
  IF stkcursor > maxstacksize THEN
    PRINT "ERROR: Stack overflow.\n"
    PushStack = FALSE
    EXIT FUNCTION
  ELSE
    PushStack = TRUE
  END IF
  bsd -= 1
END FUNCTION

...

IF NOT PushStack() THEN GOTO HandleError
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 10:53:20 PM
This is how I'm dealing with GOSUBs that don't call anything other than the HandleError: routine.
That's OK for FBLisp too.

We need also to restore the former HandleInternalError: but in relation to the actual errors that file read may encounter today. The QB45 errors were mostly concerned with floppies while a modern handler should work for other disk drives like e.g. HDD where XBLisp is most probably going to read its files from.

Quote
show what this thing is capable of
Hehe so you want me to be doing it? But John, I'm a GUI guy, I don't really see why you are all so happy with this ugly black hole in your monitors. ;D

Quote
Code: [Select]
0](eq? (list 'a 'b) (list 'a 'b))
()
BTW this one seems to be correct as per the PDF but I can't quite see the reason why. And the PDF doesn't describe this case clear enough to catch the idea behind "however, lists may look similar, but not be identical"... ??? Is it because the one on the left is the first term in this evaluation while the one on the right is the second one? Mystery...
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 11:01:21 PM
Hello Rob,

Can you teach us why exactly this expression


Code: [Select]
(eq? (list 'a 'b) (list 'a 'b))
evaluates to FALSE?

Thank you!
Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 11:10:13 PM
Quote
But John, I'm a GUI guy, I don't really see why you are all so happy with this ugly black hole in your monitors.

I have lofter goals. I would like to see this combo be used as a introduction to programming. Teach traditional BASIC then follow up with Lisp using SBLisp as a model for how one might write a Lisp interpreter. The C BASIC extension modules might be a way to roll teaching C in to this.If I can get Arthur interested, he is in a perfect position to make course matter out of this. Well, that's the plan anyways.

I also think this way of dealing with function errors will allow us to expand on the error reporting with more info.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 11:33:12 PM
Hehe, can we write a console Tetris or Space Invaders in this XBlisp thingy and (re)register at that retro-BASIC serpentarium on account of the underlying BASIC? ;D
Title: Re: Lisp in Basic
Post by: JRS on August 15, 2014, 11:34:47 PM
Hehe, can we write a console Tetris or Space Invaders in this XBlisp thingy and (re)register at that retro-BASIC serpentarium on account of underlying BASIC? ;D

Leave the toys to the boys.  We will be able to do games and other graphic programming as soon as we get the SDL GFX extension module plugged into SBLisp.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 15, 2014, 11:36:35 PM
... a console Tetris or Space Invaders ...


(http://www.quanglewangle.com/wordpress/wp-content/uploads/2011/07/citrus.gif)    (http://www.victornils.net/tetris/img/vitetris050-brackets.png)

;)
Title: Re: Lisp in Basic
Post by: RobbeK on August 16, 2014, 01:35:11 AM
Hi John , Mike ...

Yes  , they are isomorphic but they do not share the same memory location (pointer),   so they do not "eq"

(setq a '(something))
(setq b a)

(eq a b)  -> T   (these share the same memory location)   : you have to use equal for isomorphic compare.   (and = for numbers).

Mr Lutz Mueller from NewLisp was able to condensate this potpourri in one single =  (but I think you need lexical scoping then - while CL is dynamical )

https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node74.html

This comes with an even more severe warning about Lisp (espec. when coming from C, Pascal etc ...  ) have a look

(setq a '(1 2 3 4))
(setq b a)

a -> (1 2 3 4)
b -> (1 2 3 4)

(incf (elt a 0))     -increment the value of the first element in the list a

a -> (2 2 3 4)
b -> (2 2 3 4)     ::)       yep, try it

(this because they point at a same object  - always try to think in pointers when working in Lisp )

The iceberg and other stories : 
---------------------------------------

The mechanism behind the code was correct , but parallel assignment seemingly not   :'(

this is the correct syntax in NewLisp

LispCode =
"(define (fib n) (if (and (number? n) (> n 2))
    (let ((L '(0L 1L)))
      (dotimes (i n)
        (setq L (list (L 1) (+ (L 0) (L 1))))) (L 0) )
     'I-can-not-do-such-a-thing.) )"

A quick example in tB  attached   :   try Fib(100.000) it will be there in less than a sec  8)   --- even interpreted ----

best Rob

(oops , yes remark the difference between (dotimes ...) between NewLisp and CL

CL   (dotimes (i x return-value) ....  )
NL   (dotimes (i x [ exceptional-end-condition ] .....  )     

My Fib starts with 1,1,2 (and indexbase 1)   -- there may be people starting their sequence with 0,1 or even 1,2  -- the nth value may be different

.
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 02:02:59 AM
Rob,

Whatever theories you wish to test between Lisp variation, please include SBLisp if you can. Lisp is confusing enough and all these different syntax variation is starting to drive me nuts.  ??? We need help testing SBLisp! A standalone Windows 32 bit version is available on the Bitbucket site.
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 02:21:25 AM
Quote
... a console Tetris or Space Invaders ...

My belief is that you should never lose your console skills and control. When the GUI fails, you are left with a console to recover.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 03:06:28 AM
John,

Please take the following seriously.

When my Windows GUI fails me, it means I should get dressed, go out, and buy me a new monitor and/or video card.

I haven't had a single GUI crash under any of my Window's in years though it is GUI programs that I'm developing and debugging all the time.

Running a console in Windows is like "driving" a Bentley that's tied to a horse's tail.

When your Linux GUI fails you, it means you're running yet another home brewed desktop manager and you should immediately either roll back by some 5 to 10 updates of your kernel to find the one that would be compatible with your GUI, or abandon the GUI idea altogether and subside to your telety.... oh, excuse me, your terminal.

The only exception to this bad omen of the Linux world is elementaryOS which owes its graphical stability to the extreme simplicity of its basic functionality. I'm using it now gladly and you know I almost fell in love with this distro the moment I saw its Luna release. But I spent two weeks taming it to the gait that would be suitable for my needs. I believe you saw my desktop screenshots, didn't you.

I am firm in my attitudes but I can also admit my fallacies whenever I come to see the reality around me has changed. But nothing's gonna take me 30 years back to the times when I first sat in front of a Soviet remake of a DEC PDP-11 with a duo-color CRT TTY -- except for Armageddon. But then, there will be hardly any machinery available if or when that happens.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 03:37:57 AM
Rob,

Thanks a lot for your explanation on EQ?. So it evaluates not only pure similarity of their structure and data stuffing, but also implies complete identity of object instances being evaluated. In fact, it evaluates to TRUE only if it is one and the same memory object that these two different terms are referring to.

FBSL has a range of comparison operators to denote different "levels" of similarity of objects:

-- = checks for the equality of magnitudes;
-- == checks for the equality of both magnitudes and data types; and
-- Is checks if a given name references a given object.

So Is would be FBSL's closest analog to LISP's EQ?. Understood.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 03:56:50 AM
And Rob,

I would also like to know exactly why newlisp.dll is so fast to calc the fibonumbers. Is it because your iterative algo is mathematically (i.e. conceptually) so much faster than the recursive algorithm that we're using for our tests?
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 09:02:14 AM
Quote
Running a console in Windows is like "driving" a Bentley that's tied to a horse's tail.

I agree! The Windows console experience is pitiful. Linux is much better in that area. If I wasn't a software developer, I would be a click & touch person as well. I could use the MySQL console interface which is a traditional way for creating and maintaining a DB. I prefer phpMyAdmin and will go through the extra effort of setting up an Apache server just for that feature alone. We all have our own way of defining comfortable.

XBLisp - The only scriptable (see JRS dictiionary) Lisp interpreter you can customize to fit your needs.

Title: Re: Lisp in Basic
Post by: Charles Pegge on August 16, 2014, 10:14:33 AM
Windows Console? :)

(http://thumbsnap.com/s/pHGiNB0Z.jpg)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 10:16:45 AM
Quote
... a console Tetris or Space Invaders ...

... or something yet less demanding e.g. like this little thingy.

That's your special to work out your fingers in the Windows console. Left/Right arrows to play, Escape to exit. :)


Quote
Windows Console? :)

Haha, exactly! ;D


.
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 10:34:45 AM
Quote from: Charles
Windows Console?

I have the same feelings when using the 32 bit only line of Microsoft's premier 64 bit developer tools. PowerBASIC also followed this development trend. (16 bit patched DOS compiler generating hand crafted 32 bit (recently added) dead code removed binaries)
Title: Re: Lisp in Basic
Post by: RobbeK on August 16, 2014, 10:37:13 AM
Hi Mike,

Yes ,  eq means the pointers have the same value -- however , all this stuff is somewhat a glimpse inside Pandora's box, some things may behave differently compiled versus interpreted --  to get warp speed CL sometimes makes a lot of copies of data in its memory ...   

Yes,  it's the iteration that gives it this speed -- the abstraction I used (not bad , I think )  is   Fib::(a b) -> (b a+b).

Those fib numbers have some strange characteristics -- tried something (attach)  :
When you square the Fib numbers and represent these by square surfaces, you can connect them so they can cover an infinite surface without any gaps  ...  ( c the demo --  oops another big file  ,  GCL in interpreted mode , slowed down a lot so one can see what's happening )

best Rob


.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 10:53:40 AM
If I wasn't a software developer, I would be a click & touch person as well.

Wait wait...

Would you elaborate a little more on the logical accents implicit in that quotation of yours, sir?

Should I understand it such that since I am a click & touch person, I can not be regarded as a software developer? Should I go now from where I don't belong quietly closing the door behind me so as not to distract you from your creative thought processes, John?

Or does my English just slip me here and I'm seeing things that aren't there?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 11:03:18 AM
Thanks again, Rob, for your clarifications and the abundance of visuals to satisfy my poor unenlightened click & touch lamer soul... :'(

:D
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 11:03:50 AM
Quote from: John
We all have our own way of defining comfortable.

I use the same OS's and tools everyone else uses with varying levels of success and desire to continue along certain paths. The computing industry is too unstable right now to be circling wagons looking for protection and relief.

 
Title: Re: Lisp in Basic
Post by: Ed Davis on August 16, 2014, 12:07:28 PM
Hehe, can we write a console Tetris or Space Invaders in this XBlisp thingy and (re)register at that retro-BASIC serpentarium on account of the underlying BASIC? ;D

Don't forget console Star Trek there is even a Lisp version!
http://www.dunnington.u-net.com/public/startrek/ (http://www.dunnington.u-net.com/public/startrek/)
http://www.takeoka.org/~take/trek/trek-man-e.html (http://www.takeoka.org/~take/trek/trek-man-e.html)

(links provided by one of the retro-BASIC serpentarium's)

(who also freely admits to preferring the command line on Windows/Linux and before that on VMS/MVS/CMS)   
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 03:28:00 PM
Another round of code restructuring, combining and dead code removal. Before any more of this is attempted, a clear understanding of why changing what is remaining in GOSUB form could be better optimized in another other form.

Current source is on Bitbucket (https://bitbucket.org/ScriptBasic/sblisp).

Visual changes:


It seems to be working. PLEASE TEST !!!
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 08:19:56 PM
http://www.takeoka.org/~take/trek/trek-man-e.html
(... preferring the command line on Windows ...)

Hi Ed,

Thanks for the links!

Once our XPLisp is capable of running this ASCII art LISP Star Treck code, I'll consider my LISP mission complete. I also promise to present you with a Gold Edition Console Special then. :)


PLEASE TEST !!!

Hi John,

PLEASE HELP !!! all ye who enter here. (c)

Would you accept help from humble point & click lamer nobodies trespassing the sacred lands of Holy Mother Console and Divine Almighty Terminal?

:)

Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 08:23:08 PM
Quote
Would you accept help from humble point & click lamer nobodies trespassing the sacred lands of Holy Mother Console and Divine Allmighty Terminal?

You did send that check or is the mail just a little slow?  ;D
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 08:26:09 PM
Is F compliant with LISP syntax?

(Just downloaded. Need time to test.)
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 08:28:31 PM
Is F compliant with LISP syntax?

That's how it works if CL and ECL.

Scheme vs. Common Lisp (http://www.cs.utexas.edu/~novak/schemevscl.html)

initdr.scm
Code: [Select]
; initdr.scm              Gordon S. Novak Jr.               31 Aug 00

; Definitions to add to Dr. Scheme: add the following to your file:
; (load "initdr.scm")

(define pi 3.1415926535)
(define (1+ n) (+ n 1))
(define (1- n) (- n 1))

; While-Do macro: (while c s1 ... sn)
; Example:  (let ((n 0)) (while (< n 3) (write n) (newline) (set! n (1+ n))))
(define-macro while (lambda (c . s)
  (list 'do '() (list (list 'not c)) (cons 'begin s))))

; dotimes as in Common Lisp
; Example: (dotimes (j 3) (write j) (newline))
(define-macro dotimes (lambda (args . s)
  (let ((maxvar (gensym 'dotimes-count)))
    (list 'do
          (list (list (car args) 0 (list '+ 1 (car args)))
                (list maxvar (cadr args)))
          (list (list '>= (car args) maxvar)
                (if (null? (cddr args)) #f (caddr args)))
          (cons 'begin s)) ) ))

; dolist as in Common Lisp
(define-macro dolist (lambda (args . s)
  (let ((lstvar (gensym 'dolist-ptr)))
    (list 'do
          (list (list lstvar (cadr args) (list 'cdr lstvar))
                (list (car args) #f) )
          (list (list 'null? lstvar)
                (if (null? (cddr args)) #f (caddr args)))
          (cons 'begin (cons (list 'set! (car args) (list 'car lstvar))
                             s)) ) )))

; Versions of standard Lisp functions in Scheme

(define (copy-list l)
  (if (pair? l)
      (cons (car l) (copy-list (cdr l)))
      l))

(define (copy-tree x)
  (if (pair? x)
      (cons (copy-tree (car x))
            (copy-tree (cdr x)))
      x))

; Simple subst similar to copy-tree
(define (subst new old tree)
  (if (pair? tree)
      (cons (subst new old (car tree))
            (subst new old (cdr tree)))
      (if (eqv? old tree)
          new
          tree)))

; More efficient subst
(define (subst new old tree)
  (if (pair? tree)
      (let ((left (subst new old (car tree)))
            (right (subst new old (cdr tree))))
        (if (and (eq? left (car tree))
                 (eq? right (cdr tree)))
            tree
            (cons left right)))
      (if (eqv? old tree)
          new
          tree)))

; Simple sublis similar to copy-tree
(define (sublis alist tree)
  (if (pair? tree)
      (cons (sublis alist (car tree))
            (sublis alist (cdr tree)))
      (if (assv tree alist)
          (cdr (assv tree alist))
          tree)))

; More efficient sublis
(define (sublis alist tree)
  (if (pair? tree)
      (let ((left (sublis alist (car tree)))
            (right (sublis alist (cdr tree))))
        (if (and (eq? left (car tree))
                 (eq? right (cdr tree)))
            tree
            (cons left right)))
      (let ((new (assv tree alist)))
        (if new
            (cdr new)
            tree) ) ) )

(define (intersection x y)
  (if (pair? x)
      (if (memv (car x) y)
          (cons (car x) (intersection (cdr x) y))
          (intersection (cdr x) y))
      '()))

(define (union x y)
  (if (pair? x)
      (if (memv (car x) y)
          (union (cdr x) y)
          (cons (car x) (union (cdr x) y)))
      y))

(define (set-difference x y)
  (if (pair? x)
      (if (memv (car x) y)
          (set-difference (cdr x) y)
          (cons (car x) (set-difference (cdr x) y)))
      '()))

(define (subset pred lst)
  (if (pair? lst)
      (if (pred (car lst))
  (cons (car lst)
(subset pred (cdr lst)))
  (subset pred (cdr lst)))
      '() ) )

(define (subset? x l)
  (if (pair? x)
      (and (memv (car x) l)
   (subset? (cdr x) l))
      (null? x)) )

(define (every pred lst)
  (if (pair? lst)
      (if (pred (car lst))
  (every pred (cdr lst))
  #f)
      #t) )

(define (some pred lst)
  (if (pair? lst)
      (or (pred (car lst))
  (some pred (cdr lst)))
      #f))

(define (nconc x y)
  (define (nconc2 x y)
    (if (pair? (cdr x))
        (nconc2 (cdr x) y)
        (set-cdr! x y)))
  (if (pair? x)
      (begin (nconc2 x y) x)
      y) )

(define (nreverse x)
  (let ((last '()) (tmp '()))
    (while (pair? x)
      (set! tmp (cdr x))
      (set-cdr! x last)
      (set! last x)
      (set! x tmp))
    last))

; Time the execution of the specified form.
(define-macro time (lambda (form)
  (let ((var (gensym 'time-var)))
    (list 'let (list (list var '(current-seconds)))
  form
  (list '- '(current-seconds) var)) )))

; Convert a floating-point number to a string of sign and at most 4 characters.
; Rounds the number so that 1.999 will come out as 2.00 , very small as 0.0 .
; numstring is written assuming that num is not too large or too small,
; i.e. num must be printable in 4 digits.
(define (numstring num)
  (let* ((numc (abs num)) (sign (if (< num 0) -1 1)) (exponent 0))
    (if (< numc 1.0e-6)
"0.0"
(begin
  (if (< numc 1.0)
      (begin (while (< numc 100)
    (set! numc (* numc 10))
    (set! exponent (1- exponent)))
     (set! numc (* (round numc) (expt 10 exponent))) )
      (set! numc (* numc 1.0001)))
  (if (< sign 0)
      (string-append "-"
     (substring (number->string numc) 0
       (min 4 (string-length (number->string numc)))))
      (substring (number->string numc) 0
(min 4 (string-length (number->string numc))))) ) ) ))

; additions thanks to Michael Bogomolny:
(define (test-expression expr)
  (display "> ") (write expr) (newline)
  (write (eval expr)) (newline) (newline) 'ok)

(define (turnin lst)
  (if (null? lst)
      'done
      (begin
         (test-expression (car lst))
         (turnin (cdr lst)))))

(define some? some)
(define every? every)
(print-vector-length #f)

(require-library "trace.ss")

; was drgraphics.scm       Gordon S. Novak Jr.              24 Aug 00

; Some graphics routines for DrScheme:

; The following is for DrScheme version 102:
(require-library "graphics.ss" "graphics")

; These routines are compatible with MacGambit and use the
; following conventions:
;    (0,0) is at the center of the window
;    +y is upward.
; You can change the size of the drawing window by changing
; the parameters *hsize* and *vsize* below before starting.

; Thanks to Dustin Friesenhahn for adding color.

; (clear-graphics)           ; erase the drawing window
; (position-pen x y)         ; move the pen to (x,y) without drawing
; (draw-line-to x y)         ; draw from current pen position to (x,y)
; (graphics-text string x y) ; draw the string in the window at (x,y)
;    e.g. (graphics-text "Hi, Mom!" 0 0)

; DrScheme specific function
; (graphics-string-size str) ; returns list (width height) of str
;                            ; in integer units of pixels

(define *hsize* 409)         ; horizontal size of drawing viewport
(define *vsize* 428)         ; vertical size of drawing viewport
(define *xoffset* 200)       ; x offset of coordinates
(define *yoffset* 200)       ; y offset of coordinates
(define *vp* #f)             ; viewport
(define *lastpt* #f)         ; last point
(define *color* (make-rgb 0 0 0))  ; init to black

; Use the viewport *vp* or open one if needed
(define (viewport)
  (or *vp*
      (begin
(open-graphics)
(set! *vp* (open-viewport "CS 307" *hsize* *vsize*))
(clear-graphics)
*vp*)))

(define (clear-graphics)
  ((clear-viewport (viewport)))
   (position-pen 0 0) )

; fix a number to be an exact integer
(define (fix x)
  (if (and (integer? x)
   (exact? x))
      x
      (if (exact? x)
  (round x)
  (inexact->exact (round x)))))

; convert from upward y to downward y as used by DrScheme
; MacGambit uses center of window as (0,0)
(define (yconvert y) (fix (- *yoffset* y)))
(define (xconvert x) (fix (+ *xoffset* x)))

; position the pen to specified point
(define (position-pen x y)
  (or *vp* (viewport))
  (set! *lastpt* (make-posn (xconvert x) (yconvert y))))

; draw a line from last point to specified point
(define (draw-line-to x y)
  (let ((newpt (make-posn (xconvert x) (yconvert y))))
    (begin
      ((draw-line (viewport)) *lastpt* newpt *color*)
      (set! *lastpt* newpt))))

; draw a string beginning at specified (x, y)
(define (graphics-text string x y)
  ((draw-string (viewport))
     (make-posn (xconvert x) (yconvert y))
     string *color*))

; DrScheme specific graphics-string-size
; returns list (width height) of a string in pixels
; Michael Bogomolny - spring 2001
(define (graphics-string-size str)
  (let ((temp ((get-string-size (viewport)) str)))
    (list (fix (car temp))
          (fix (cadr temp)))))

; set color to be used in drawing
; Each color value must be between 0 and 1.
(define (set-color! red green blue)
  (if (and (number? red) (>= red 0) (<= red 1)
   (number? green) (>= green 0) (<= green 1)
   (number? blue) (>= blue 0) (<= blue 1))
      (set! *color* (make-rgb red green blue)) ) )
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 08:41:04 PM
Quote
(Just downloaded. Need time to test.)

Thank You !
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 08:52:35 PM
Seems running just fine here. No mem leaks or uptime regression detected.

BTW sblisp.exe in the repo seems not updated -- still prints Bye!.

Thanks for good work, John!
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 09:09:36 PM
Quote
BTW sblisp.exe in the repo seems not updated -- still prints Bye!.

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ cd ~/repos/sblisp
jrs@laptop:~/repos/sblisp$ git add SBLisp_exe.zip
jrs@laptop:~/repos/sblisp$ git commit -m "Updaded Windows 32 standalone SBLisp.exe"
[master bc32b87] Updaded Windows 32 standalone SBLisp.exe
 1 file changed, 0 insertions(+), 0 deletions(-)
 rewrite SBLisp_exe.zip (96%)
jrs@laptop:~/repos/sblisp$ git push
Password for 'https://ScriptBasic@bitbucket.org':
To https://ScriptBasic@bitbucket.org/ScriptBasic/sblisp.git
   619c627..bc32b87  master -> master
jrs@laptop:~/repos/sblisp$



.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 09:27:35 PM
Thanks for the update, John.

Seems like we are having a little uptime regression here. SB's (fibonacci 20) now runs some 11.7 seconds against 10.7 seconds for the former pre-Sub versions. Perhaps that will be the penalty for better structured code.

I haven't yet updated FBLisp with your Subs. I'll see if my uptime increases too as soon as I do. I'll inform you here when I'm through.

Go have a rest. :)
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 09:33:27 PM
Quote
Go have a rest.

Just trying to find Scheme examples that work to post. I hope others do the same.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 09:37:37 PM
John,

I think I should put OxyLISP aside for the time being. It still takes too much of my effort. I'd rather spend more time on trying to enrich the structure and vocabulary of the two versions that are currently functioning. What do you think?

hope others do the same.

Others are enjoying Sunday morning while someone else is still stuck in Saturday night. :D
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 09:50:25 PM
Quote
I'd rather spend more time on trying to enrich the structure and vocabulary of the two versions that are currently functioning. What do you think?

I would let Charles take the current SBLisp source and try to make it work. As a possible side benefit he may find a better way than the GOSUBs we are currently pondering.

Quote
Others are enjoying Sunday morning while someone else is still stuck in Saturday night.

Helps me dodge everyone else's mistakes.  8)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 10:02:49 PM
I would let Charles take the current SBLisp source and try to make it work.
Well, I wouldn't. Firstly, his Lispish is our competitor and secondly, I'm ashamed to publish non-working code. That would be somehow unbecoming even if you don't take me for a developer. :)

Quote
As a possible side benefit he may find a better way than the GOSUBs we are currently pondering.
We've already discussed those better ways while fiddling with Ed's Toy interpreter. As a result of our discussion, FBSL is now stuck up to its ears with all sorts of such better ways.

Quote
You did send that check or is the mail just a little slow?
Nope, it isn't. Everything was done in just one lo-o-o-o-o-o-ng twinkling of the eye.  :P
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 10:08:11 PM
Quote
Well, I wouldn't. Firstly, his Lispish is our competitor and secondly, I'm ashamed to publish non-working code.

Pretend you're Peter and just keep it to yourself.  :-*

Quote from: john
I would let Charles take the current SBLisp source and try to make it work.

I have had very few issues porting O2 code to SB. (Peter's games & examples)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 16, 2014, 11:23:16 PM
Pretend you're Peter and just keep it to yourself.  :-*

Noooooo John,

That's not my style. The Toy interpreter just ran in FBSL out of the box whereas its O2 counterpart wouldn't. So I put it aside for some two weeks and when I came back later, it just worked with Charles' latest O2 from the Wizard at the top of this page. I posted the sources immediately.

There's nothing secret in XPLisp either. I will only be glad if someone gets it working in Oxygen before I do. Who knows, perhaps that someone may even appear to be you, the congenital terminal code developer. :P
Title: Re: Lisp in Basic
Post by: JRS on August 16, 2014, 11:54:11 PM
Rob,

Can you create a simple plot or graphic (Mandelbrot would be great) in SBLisp with the following API?

Code: [Select]
Lisp::SBL_Init()
Lisp::SBL_CmdStr()
Lisp::SBL_CmdFile()
Lisp::SBL_Close()

Note: The SBL_CmdStr() & SBL_CmdFile() module functions will return a string with the result of the call. The SBL_Close() call is optional if a SBLisp (quit) is embedded in your script.

I will be using Script BASIC and the SDL GFX extension module for the graphics part. I hope to use the pattern matching SB functions to parse the return SBLisp response strings.

TIA
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 17, 2014, 07:20:17 AM
Hehe John,

So I was not totally nuts and that recursive GOSUB nightmare was not entirely my hallucination: LispEval:, LispPrint: and ReadSExpSeq: are recursive GOSUB's.

I'm currently trying to finish your work on GOSUB elimination. Nothing much to report yet.
Title: Re: Lisp in Basic
Post by: RobbeK on August 17, 2014, 07:50:19 AM
HI,

Yes, I can write something -- maybe (attached) is a candidate ( ? , please be frank -- sometimes , these maths are much less spectacular as I think  ;)

It's interesting because :

- it's sets up prime numbers from scratch
- it sets up a pixel-spiral that in symbolic language can be written as U L 2D 2R 3U 3L 4D 4R 5U 5L  ..  up,down, left ; right (p.e. 4R means 4 times to the right ) , it's an example of mixing the two patterns.
- the use of complex numbers as lists   (Unlike CL, Bigloo comes without complex numbers )

so, written in Bigloo Scheme   -
buttons :

- a prime spiral (sometimes used to find linear correlations --  you can see some lines containing more primes than others - Euler made a few formulae   (without computer of course)
- the Gaussian primes (complex prime numbers).

However , I may need your help for something .. these graphics are slow and using a faster method (by building rgb arrays) is very difficult (both in CL and Scheme).   It needs pointers (only in NewLisp I can do this because it has (address ....  ))

I want to use this : void j drawimagesource ( int obj , int x , int y , int w , int h , int* r , int* g ,int* b );

(those pointers are the problem ... )

Bigloo has a C-interface, but I don't understand it ... there's something about setting up pointers - with accessors and mutators   , but I don't get how to communicate with these.

http://www-sop.inria.fr/indes/fp/Bigloo/doc/bigloo-28.html#The-C-interface

(there's no way (afaik) Scheme or CL will give an address of any allocated memory  )

best Rob



.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 17, 2014, 08:18:58 AM
Hi Rob,

Quote from: John
Can you create a simple plot ... in SBLisp ...

If I understand John correctly, what he is trying to ask you for all this time is some useful script in the LISP dialect that we have translated from QBasic 4.5 as described in the PDF.

SBLisp stands for Scheme BASIC Lisp and that's John's SB version of QBasic LISP while mine is FBLisp that stands for Freestyle BASIC Lisp.

The LISP code that you're posting here is currently of no practical use to us because neither SBLisp nor FBLisp currently support any iterative constructs except (for-each).
Title: Re: Lisp in Basic
Post by: JRS on August 17, 2014, 08:48:03 AM
Rob,

What I'm looking for is this to be converted into Scheme BASIC Lisp (SBLisp) so I can call it as a SB Lisp extension module function.

Mandelbrot Iterator
Code: [Select]
besFUNCTION(gfx_Mandelbrot)
  DIM AS double cx, cy, zx, zy, tp;
  DIM AS int iter;
  besARGUMENTS("rri")
    AT cx, AT cy, AT iter
  besARGEND
  DEF_WHILE (zx * zx + zy * zy < 4 AND iter > 0)
  BEGIN_WHILE
    tp = zx * zx - zy * zy + cx;
    zy = 2 * zx * zy + cy;
    zx = tp;
    iter = iter - 1;
  WEND
  besRETURN_LONG(iter);
besEND

Here is the Script BASIC code calling the C BASIC SDL GFX extension module version of the Mandelbrot iterator. What I would like to do is call the SBLisp version of the iterator.

Code: [Select]
' ScriptBasic GFX - Mandelbrot

IMPORT gfx.inc

s = gfx::Window(640,480,"ScriptBasic GFX Mandelbrot")
ts = gfx::Time()
FOR y = 0 TO 479
  FOR x = 0 TO 639
    cx = (x - 320) / 120
    cy = (y - 240) / 120
    rit = gfx::Mandelbrot(cx, cy, 510)
    gfx::PixelRGBA s, x, y, rit * 12, rit * 8, rit * 4, 255
  NEXT
NEXT
te = gfx::Time()
gfx::stringColor s, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0x000000ff
gfx::Update
WHILE gfx::KeyName(1) <> "+escape"
WEND
gfx::Close

(http://files.allbasic.info/ScriptBasic/gfx/sbgfxu64_mandelbrot2.png)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 17, 2014, 09:10:48 AM
John,

Your CBASIC code is written for an optimizing C compiler. Be forewarned it's going to be slow as hell in an interpreter, be it BASIC or SBLisp or whatever. Remove duplicate zx*zx and zy*zy recalculations from the while loop.

You're making the exact same mistake that Peter and others were making in their Oldschool Plasma code.
Title: Re: Lisp in Basic
Post by: JRS on August 17, 2014, 09:15:02 AM
Thanks Mike for the tip and your new adventure in GOSUB madness. I know it's going to be slow compared to the C BASIC version but I thought it would be a good function to help us optimize the XBLisp efforts.

Quote
You're making the exact same mistake that Peter and others were doing in their Oldschool Plasma code.

Correction: This Mandelbrot iterator is a verbatim port of the code posted on this forum. I take no ownership in its creation.
 
Title: Re: Lisp in Basic
Post by: RobbeK on August 17, 2014, 10:34:14 AM
Hi John , Mike ,

Downloaded the SBLisp :

- there is no iterative mechanism   (for-each is a mapping device ).
- named-let (the pseudo-iterative Scheme mechanism does not exist)
- there is no (begin...  )  to mark a block, which is necessary inside the if macro , the problem is
    (if cond x y)   where both x and y is one single expression -- to overcome this
     -  in Scheme    (if cond (begin .... )   (begin ....))
     - CL   has several mechanisms   block ,  prog1 , ... progn
- However :  there is (cond  ... ) to replace previous , it accepts more than one expression / condition
- It does tail recursion perfectly
- This can be expanded that the lambda expression contains an accumulator and an iterator value , it is of course possible to add more parameters if several conditions are needed  (like while calculating a point of a fractal , there are 2 parameters : a maximum number of iterations and an orbit limit (p.e.   x²+y²)

an example of ordinary tail-recursion is attached called ff
and an extended tail-recursion which contains an iterator and an accumulator.
(with this everything is possible)
However , recursion (if not using a "smart" compiler that converts it into iterations into the native code) results in veeery slow run times. As Mike remarks, the Mandelbrot may not be something for the show-case.
The primes-sieve *is*  -- no problem to write & this also while this will give reasonable execution time.

(attached :  factorial    - TR recursion  - TR recursion + aux parameters.

best Rob

.
Title: Re: Lisp in Basic
Post by: JRS on August 17, 2014, 10:43:29 AM
Thanks Rob!

I should have something to show soon.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 17, 2014, 11:01:46 AM
This Mandelbrot iterator is a verbatim port ...
This is exactly why I mentioned Peter; you weren't on the alert while porting.


Quote
... of the code posted on this forum.
This forum deals with code compilable to native code. Even so it can contain pitfalls especially when compiled by Oxygen that has no optimization mechanisms to rearrange pieces of inefficient code automatically. It cost Peter 20% of his FPS and I don't know how much these duplicate zx*zx and zy*zy would cost the O2 Mandelbrot code creator whoever that was.

Anyway, my obligation was to point that out. Your right is to accept or ignore my points. I'm not going to do any more benchmarks only to prove again and again what has already been proven.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 17, 2014, 11:12:03 AM
Rob,

Thanks a lot for your brief survey and a simple test of a couple of XBLisp features. Still I would like to ask you, while you are at it, to provide us with some usable code written in XBLisp to have a Mandelbrot set printed out to the console in the form of ASCII art.

I will provide you with very short but complete equivalent programs written in C and BASIC and I will attach a reference picture of what they would do in less than a second in your console.

Please give me 5 minutes or so to have it posted here.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 17, 2014, 11:48:19 AM
Here comes the script to use, snapshot for reference, and executable to get the feeling of speed. I don't think such a script would run so very slow if ported to XBLisp. This is of course if it can be ported at all given the existing vocabulary.

But something's telling me you can invent means and ways to cut corners... :)

Thank you!

Code: [Select]
#APPTYPE CONSOLE

MandelB()
MandelC()

PAUSE

SUB MandelB()
DIM i, j, r, x, y
DIM k = 1
DIM s = " .:-;!/>)|&IH%*#" // leading space inside quotes!

FOR y = -16 TO 15
FOR x = 0 TO 78
PRINT s{INCR(k BAND 15)} ; // no new line! // this is equivalent to s[(k & 15)] in C but here s{n} starts at n = 1 contrary to C's s[n] where n would start at 0
LET(i, r) = 0 // this is equivalent to i = r = 0 in C
FOR k = 0 TO 111
j = r ^ 2 - i ^ 2 - 2 + x / 25
i = 2 * r * i + y / 10
r = j
IF j ^ 2 + i ^ 2 > 11 THEN EXIT FOR
NEXT
NEXT
PRINT // new line
NEXT
END SUB

DYNC MandelC()
void main()
{
float i, j, r;
float x, y = -16;
int k = 1;
while (puts(""), y++ < 15) {
for (x = 0; x++ < 84; putchar(" .:-;!/>)|&IH%*#"[k & 15])) { // leading space inside quotes!
for (i = k = r = 0;
j = r * r - i * i - 2 + x / 25, i = 2 * r * i + y / 10, j * j + i * i < 11 && k++ < 111;
r = j);
}
}
}
END DYNC

.
Title: Re: Lisp in Basic
Post by: RobbeK on August 17, 2014, 12:38:30 PM
Runs like greased lightning --  8)

OK, I'll tinker something (tomorrow , I have some time to do so )  -- it's infact easier than the prime sieve (and if some time I'll make one too --  the idea is clear  (mapping a function that gives the number of divisors over a list -- it is possible, I checked the parts to do so  :)

If you should have some time  -- just to confirm this is sensible talk

http://www-sop.inria.fr/indes/fp/Bigloo/doc/bigloo-28.html#The-C-interface

I need those buffered graphics , otherwise I can better switch to language thas can address those arrays :

look at the difference in speed    (caused by the graphics  1 call to the interface i.o. 640000 times)  quickly rewritten
|
|
v     (these're 640000 complex numbers tested on primality )



.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 17, 2014, 01:41:50 PM
OK, I'll tinker something (tomorrow , I have some time to do so )  -- it's infact easier than the prime sieve (and if some time I'll make one too --  the idea is clear  (mapping a function that gives the number of divisors over a list -- it is possible, I checked the parts to do so  :)
Thanks for the great news! I'll be keeping my fingers crossed. :)

Quote
If you should have some time  -- just to confirm this is sensible talk .... ==> etc. etc. etc.
Whom are these questions addressed to? Yes, your new program runs visibly much faster than the previous one. And yes, the link points to the description of how the Bigloo native code compiler would treat mangled and unmangled names from C object files and vice versa when linking the resultant executable. And yes again, it describes the syntax to use in both Bigloo and C scripts to generate object names that would allow this foreign interface to pass data in both directions.

Now please, your needs and motives should be just a little more precise:

1.
Quote
I need those buffered graphics
Where do you need them, please? In thinBasic, OxygenBasic, ScriptBASIC, FBSL, SBLisp, FBLisp, Lispish or anywhere else? What environment exactly are we talking about here?

2.
Quote
otherwise I can better switch to language thas can address those arrays
Switch over from what language, please? I see you coding in many languages at once so which one of them will you have to abandon?

Can you please formulate the following:

1. What is the ultimate goal that you're pursuing?

2. What instruments can people on this site provide you with to achieve your ultimate goal?

3. In case we can't provide the exact instruments for your needs, how can we better assist you in more minor matters that will still make it easier for you to find and/or acquire the appropriate instruments to achive your ultimate goal?

Sorry for being so inquisitive but I do need a clearer idea of the issues above to be able to say in what way my modest abilities can be of any help to you. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 17, 2014, 02:33:27 PM
John,

I've cut those Siamese twins apart with only some 120 lines of code being reduplicated in the two major Subs. The code can also be merged into minor common Subs later on because I don't want to add yet one more nesting level at the moment. The operation was a success but the patient is still in a coma. There are at least four levels of Sub nesting that should be carefully sorted out to allow clean returns from multiply nested levels straight to the error handler and back into the program main loop -- LispReadEvalPrintLoop(). LispEval() also appeared recursive at many points within itself.
Title: Re: Lisp in Basic
Post by: JRS on August 17, 2014, 02:36:27 PM
Great work Mike!

OT Cowboy? No. I don't eat Bubba Burger's and about the only thing I like country is the women.  ;)

P.S.

I also owned a 64 Imperial back in 74. I Liked that one the best. This one is the right color.

(http://images1.snapfish.com/34792%3C9%3A8%7Ffp356%3Enu%3D3238%3E7%3C3%3E295%3EWSNRCG%3D3233%3A84%3A3%3A748nu0mrj)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 17, 2014, 03:03:13 PM
:D

John, those designs are always so utterly alien to a European! But that deep green color is pleasing and that sense of prideful ownership isn't totally uncommon here either.

And please don't get me wrong. I'm not really trying to hurt anyone's feelings; it's simply some light and cheerful teasing just to keep the conversation going. :)

I'm a little tired of the work done tonight and I guess I'll be finishing it off tomorrow. I'm afraid of some incidental typo that may unnecessarily complicate matters for me. The subs are still huge and clumsy to work with.

[EDIT] Hey John, I forgot to ask you if SB has some sort of macro functionality similar to #DEFINE or MACRO or whatever? Those could shorten the code by maybe one third of its current size.
Title: Re: Lisp in Basic
Post by: JRS on August 17, 2014, 03:14:18 PM
I drive a practical multi-purpose vehicle. Those were toys I just had fun with. A great party car. The stories I could tell.  :-X

I can feel your pain when it stops working. Luckily my bug was a misplacement of a label after converting a GOSUB to a SUB.
Title: Re: Lisp in Basic
Post by: JRS on August 17, 2014, 03:25:18 PM
There is MODULE / END MODULE which makes code within them its own namespace. This is how I'm exposing the Script BASIC Lisp extension module with only three calls.

Lisp::SBL_Init
Lisp::SBL_Cmd
Lisp::SBL_End   (optional)

There is no on the fly EVAL feature in SB. Peter's suggestion to Dave when it came up was create another instance of the SB pProgram object.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 17, 2014, 03:47:30 PM
That doesn't look exactly like what I'm looking for. I need sort of a preprocessing functionality that would substitute at the script parsing stage some macro name, say MYMACRO, with a succession of verbatim statements without an extra call/return framing. E.g. a INCR_CDR_ERROR macro defined and expandable as follows:
Code: [Select]
#DEFINE INCR_CDR_ERROR bsd += 1 \
IF NOT Cdr() THEN \
HandleError() \
EXIT SUB \
END IF
would spare us 4 lines in maybe a hundred places throughout the code without adding unwanted extra returns that would otherwise overlay the EXIT SUB which in fact we are after.
Title: Re: Lisp in Basic
Post by: JRS on August 17, 2014, 04:59:23 PM
I would wait for that kind of optimization once we get it over to the C BASIC extension module. I thought our goal was to get rid of GOSUB/GOTO and put everything into SUB/FUNCTION routines for the BASIC level side of the conversion?



Title: Re: Lisp in Basic
Post by: JRS on August 17, 2014, 06:26:24 PM
Quote
would spare us 4 lines in maybe a hundred places throughout the code without adding unwanted extra returns that would otherwise overlay the EXIT SUB which in fact we are after.

Can you create a custom FUNCTION/SUB for that? If we had a flow diagram I could be of more help.

Update: I might have to wait until Mike finishes the rest of the GOSUB/GOTO conversions to SUB/FUNCTION before tring to make an extension module from it. I'm still looking at ways with the current code but the interest is fading fast. I'm looking forward to what Mike comes up with for this next round.

@Charles - Can you confirm if your are or are not planning an attempt at getting the SBLisp code running in O2?


.
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 12:23:50 AM
Here is a Hello World example using C to call ECL Lisp functions. I haven't given up on SB ECL yet. There is so little documentation for embedding ECL that making progress is a slow process.

Code: [Select]
jrs@laptop:~/ecl/examples/jrs$ cat hello_ecl.c
#include <ecl/ecl.h>

int main(int argc, char **argv)  {
  cl_boot(argc, argv);
  cl_object obj=c_string_to_object("\"Hello world\"");
  cl_pprint(1,obj);
  printf("\n");
  cl_shutdown();
}jrs@laptop:~/ecl/examples/jrs$ gcc hello_ecl.c -lecl -o hello_ecl
jrs@laptop:~/ecl/examples/jrs$ ./hello_ecl

"Hello world"
jrs@laptop:~/ecl/examples/jrs$ ls -l hello_ecl
-rwxrwxr-x 1 jrs jrs 8788 Aug 18 01:18 hello_ecl
jrs@laptop:~/ecl/examples/jrs$
Title: Re: Lisp in Basic
Post by: RobbeK on August 18, 2014, 01:08:54 AM
Hi Mike,

"What environment exactly are we talking about here?  ...   "
The unnamed is always Lisp  ;)
The lack of its memory access mechanisms made me balance between an eulogy and an elegy towards Lisp at that moment of writing.

From there my question if the provided documentation was sensible.
After you positive response I studied the text (I have low experience with C .. at the job I was the only one writing in Lisp, all the others used the big c  ...

but, it's ok now .. "Übung macht den Meister"  8)

see attached , i can address allocatable memory now from within Bigloo

best Rob

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 01:10:32 AM
Hi John,

I thought our goal was to get rid of GOSUB/GOTO and put everything into SUB/FUNCTION routines for the BASIC level side of the conversion?
Quote
Can you create a custom FUNCTION/SUB for that?
Forget it. I was just looking for a more efficient way to denote pieces of repeatable code without turning it into yet another nested level of Subs. If there's no such a way, so be it.

Quote
I'm looking forward to what Mike comes up with
Resuming my work right away.

Quote
I haven't given up on SB ECL yet.
Why should you? ECL is by far more able than SBLisp and will always be.



Title: Re: Lisp in Basic
Post by: Aurel on August 18, 2014, 01:19:40 AM
Guys i am not sure but i think that i see ( one one site ..sorry i don't remeber where)
that there is a version of Lisp written in sinclair QL superBasic.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 01:23:27 AM
Hi Rob,

From there my question if the provided documentation was sensible.
Entirely sensible, precise, and comprehensive. The best of the two worlds. :)

Quote
"Übung macht den Meister"  8)
Jawohl! :)

Quote
i can address allocatable memory now from within Bigloo
Congratulations and thanks for the sample! :)

That red screen definitely has some fine structured symmetry hidden in it. Can it be revealed graphically to see if it has any aesthetic value?
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 01:24:54 AM
Quote
Why should you? ECL is by far more able than SBLisp and will always be.

Here is the API I need to use to create a SB ECL extension module in C BASIC. My ECL setup on my Ubuntu 64 bit box seems to be working fine.

 ANSI Dictionary — Common Lisp and C equivalence (http://ecls.sourceforge.net/new-manual/re14.html)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 01:27:31 AM
Hi Aurel,

Guys i am not sure but i think that i see ( one one site ..sorry i don't remeber where) that there is a version of Lisp written in sinclair QL superBasic.

Thanks for the info. Yet I think QB45 is much closer to O2/SB/FBSL than Sinclair in its syntax making it a better choice for a quick port job.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 01:35:23 AM
Here is the API I need to use to create a SB ECL extension module in C BASIC.
So what's missing to have it created?
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 01:48:46 AM
Quote
So what's missing to have it created?

Working on it. So far my tests have been successful.

The ECL API is HUGE. (see attached)

Bare bones ECL includes.
Code: [Select]
#include <ecl/object.h>
#include <ecl/external.h>
#include <ecl/cons.h>
#include <ecl/stacks.h>
#include <ecl/number.h>
#include <ecl/legacy.h>

I think we are on the right track with XBLisp. No way am I going to wrap that ECL monster.

.
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 03:00:14 AM
The only thing that make any sense with ECL is using it with C BASIC. No wrapping, just include and use the functions. SDL_gfx can be included as well. That is where Rob should be putting his efforts into. IMHO

HERE (http://files.allbasic.info/ScriptBasic/SBLisp.pdf) is a PDF listing of SBLisp color syntax highlighted from Ultra Edit. (Linux version)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 03:46:49 AM
John,

I suddenly had a very bright idea on how it all can be simplified using SB/FBSL's own ON ERROR functionality. It makes the code incompatible with OxyLISP that doesn't have an ON ERROR mechanism but that will have to wait till better times.

I'm abandoning my yesterday's work and re-writing the code once again from scratch.

P.S. I'm using FBSL's Eclecta to work with SB code. It's equipped with an automatic real time drop-down combo list of subs/functions and its syntax highlighter is perfectly suitable for the task as well. :)

P.P.S. Your current FUNCTION TestThenScan is buggy. It contains invalid returns referring to a non-existent entity CopyUsefulMemory! That's where implicit creation of variables starts to play its dirty tricks on us. ;)

P.P.P.S. Hehe, the new HandleError() implementation is working Just Great! :D Proceeding to the operation on the Siamese twins with a brand new razor sharp lancet in hand...
Title: Re: Lisp in Basic
Post by: RobbeK on August 18, 2014, 03:48:19 AM
Hi Mike,

"some fine structured symmetry hidden in it"

Set up a "dirty" zoom for a closer look  (  but , "dirty" - no recalculations , just screen copies -- will be worse every click )

Code is opitmized "  for benchmarks " now ( can slightly run faster be declaring the integers fixed ).

best Rob
(speed is good , I have my tools now  :-*, I'll work on the XBLisp this evening/night )

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 03:59:40 AM
Thanks Rob!

Rien ne va plus occurs too early... :D

I was talking about finding some coloration algo to try and reveal this symmetry visually. I wonder if this could make the plot more aesthetically attractive. You know I'm always hypnotized by interference patterns and such, especially in 3D. :)

And thanks for the good news about XBLisp too!
Title: Re: Lisp in Basic
Post by: RobbeK on August 18, 2014, 06:04:39 AM
Warming up a little for Xbisp ..

(ah, ok -- those symmetry comes from the fact that x²+y² == (-x)²+y²   etc...  (nothing that can be used for the 1.000.000$ Riemann proof  :'(  )

OK, the Lisp .. 
I noticed it misses something very elementary ,  the (cadr ... ) , it so much used it should be there (though it can be defined from things available )
My idea is consequently while I write those examples at the mean time writing a kind of ini.lisp file with often used functions.

the "cadr" means simply the second element of the list but is written as the first element of the rest (minus the first) of the list .
you have   a::  '(a b c)       (car a) ->a   (cdr a) -> (b c)  (cadr a) ->b

the nomenclature from the IBMs from the 1950s  8)


    car (short for "Contents of the Address part of Register number"),
    cdr ("Contents of the Decrement part of Register number"),
    cpr ("Contents of the Prefix part of Register number"), and
    ctr ("Contents of the Tag part of Register number"),
(wikipedia)

So, attached :
my definition of cadr  -----> (should belong in the ini.lisp file)
the way I should handle pseudo-iteration   ( I first built a helper function which does the pseudo-iteration and accumulation )

can you test the speed compared with previous ?    t.i.advance

best Rob  ,,     (will start with source txt files now -- easier to comunicate)
oops , this time the sequence starts with 0,1,1,2,3   replace in the aux. function the (car L) with (cadr L) to start at 1,1...

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 06:22:55 AM
Thanks a lot again, Rob!

Quote
sblisp wordt niet herkend als een interne
of externe opdracht, programma of batchbestand.

Please make it English, French, or German. I can't read that yet but I'm hoping to, with time and your assistance. :D

You can write whatever macro includes you like but I'm inclined to add new keywords only if they are legitimate parts of standard Scheme vocabulary. Is (cadr) officially recognized and supported in Scheme? If yes then can you also write down a full list of Scheme's other basic keywords for me that XBLisp is still missing?

P.S. You can use ; in your XBLisp code to denote comments. It isn't described in the PDF but it works.
Title: Re: Lisp in Basic
Post by: RobbeK on August 18, 2014, 07:02:13 AM
Hi Mike,

I'm from Flanders and that's my lingo (there are more people in NY than ....    ).

It is described in the standard as

--------------------------------------------------------------


library procedure: caar pair
library procedure: cadr pair

...: ...

library procedure: cdddar pair
library procedure: cddddr pair

    These procedures are compositions of `car' and `cdr', where for example `caddr' could be defined by

    (define caddr (lambda (x) (car (cdr (cdr x))))).

    Arbitrary compositions, up to four deep, are provided. There are twenty-eight of these procedures in all.

-------------------------------------------

so every combination upto c....r  , however these are called "library procedures" i.o. "procedures"  (maybe just because it are composites , nevertheless I noticed them in any Scheme ever used )

so, the caddr , is the 3rd element of a list ///  etc

(we can always name the ini.lisp something as lib.lisp in case  8)

best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 08:24:03 AM
OK Rob,

If they aren't part of standard inbuilt vocabulary but rather library procedures (or macros, for that matter), let's better keep them in a separate "library" module (ini.lisp or lib.lisp file) loadable on XBLisp start. Your XBLisp (the .exe that you have) can't recognize more than one filename to load on startup so a
Quote from: Command line
sblisp.exe lib.lisp fibonacci.lisp
command line isn't possible but I'm currently reworking its code and I will add this functionality too.
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 09:36:14 AM
Outstanding progress Mike!

I have a feeling I'm not going to be able to recolonize our kid once you get done with your course corrections.  8)

I'm going to try and get a  C BASIC version of the Mandelbrot example using SDL_gfx and ECL libraries posted. No promises!

@Rob - Can you post a Common-Lisp version of your Mandelbrot iterator so I can try this with C BASIC & ECL?

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 10:13:43 AM
Morning John,

I'm two thirds through with the fission process and everything's OK so far. While LispPrint is self-recursive and LispEval is self-recursive too, ReadSExp and ReadSExpSeq appear to be self-recursive, mutually recursive, and multiply recursive with LispEval to an unlimited depth. My yesterday's scheme simply wasn't able to cope with such unlimited interleaving and recursion in principle but my present scheme is.

And if "recolonize" in fact means "reformat" then I can assure you that my formatting is perfectly consistent with your rules.

There will however be just one request. The code now contains a few of my comments on what is being done here and there and why. Please let them stay in the sources until further notice when everything has been perfectly tested.
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 10:44:29 AM
All sounds good to me.

The reason I removed Arthur's comments was they were getting in the way with the restructure. The plans were a new code documentation effort after the dust settled. Maybe you could add WIP comments to the code in this form or something like it so they are easy to find later.

Code: [Select]
' <Mike>  ....

@Rob - Can you declare up front what Lisp project your response is addressing? Personally I only have enough mental capacity to deal with SBLisp and maybe a little left over to experiment with C BASIC and the SDL_gfx / ECL libraries under Linux 64 bit. Thanks again for helping out with these pooled resource projects.
Title: Re: Lisp in Basic
Post by: RobbeK on August 18, 2014, 01:03:30 PM
Hi John, Mike ..

A little sample -- the Mandel tomorrow (but the speed is very low -- need a few tests for the console output -- this Lisp has no strings  ??? )

@Mike -- is their an exit function ? I have completely to close my console to start over again (it refuses redefinitions - and the exe does not run in REPL mode under LispIDE ).

@John - Lisp project ?  ( the job ? - i wrote interfaces between AutoDesk's AutoCAD and Siemens CAD/CAM machinery -- but in the end I coded the complete designing from the start too -- everything running under MS DOS/Lisp   8)   - to be honnest, I sometimes uses Basic-scripts too , (but these can not reach the entities of AutoCAD's database system in depth - Lisp can ! )
I'm busy with Bigloo Scheme now, writing the Mandelbrot can be done in 15' -- if this helps ??

attach --  it loads and runs --  tried the magical mapping , it's slow - but works , feels like being in the 1970s again ...   ;)

best Rob



.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 01:06:03 PM
John,

1. Rob's last message but one regards XBLisp and concerns the instruments (user-defined procedures a.k.a. lambdas) that will help him re-create in XBLisp the BASIC ASCII Mandelbrot which I sent him yesterday. Such lambdas are available in Scheme in the form of library procedures outside the scope of its basic vocabulary. So we agreed to keep them in a separate lib.lisp file either loadable before an interactive session or includable at the beginning of a .lisp file with a (load 'lib.lisp) directive.

2. I've finished my work for today -- I got too tired and inattentive.

3. I did't add the multi-file load option yet. I think we can live without it for now because files can be added to other files in the form of includes as described in Item 1 above.

4. I succeeded in splitting the main parts of XBLisp entirely and the script should be fully working now. At least it works for me here. The only place where GoSub's still stay is the large LispEval() procedure that starts somewhere in the middle of the file. These GoSub's are entirely intrinsic to LispEval() and can be turned into standalone Function's very easily. They aren't referenced anywhere else except within LispEval() itself.

5. This code will stay compatible with OxyLISP. ;)

6. I have optimized IF conditionals wherever possible to speed up evaluation a little.

7. Please do not try to re-arrange the code (it is position-dependent) nor re-write the remaining GoSub's into Function's yourself. You don't have a clear idea yet of how error propagation from deeply nested recursion works so you may break it easily. Let me finish it off myself tomorrow.

8. Please recompile a new 32-bit SBLisp.exe and post it here for Rob and me to use in our future tests.

9. I will label my comments in accordance with your suggestion tomorrow. Apart from that, formating should be compliant with your requirements.

Thank you. I hope you'll like the results.

[EDIT] Attachment deleted due to a Linux bug
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 01:09:12 PM
Rob,

1. The exit function is (quit). Everything is described in the PDF file. Have you got it? Alternatively, SBLisp.exe will break on ^C (Ctrl+C) allowing you to exit but keep the console open.

2. No, redefinitions aren't allowed.

3. Please wait till John posts shortly a new SBLisp.exe here on the forum for you and me to use.

Thanks! :)


P.S. I'LL BE DAMNED! YOUR PROGRAM WORKS! :D

You may use a -D switch in your command line -- it will then show when and how garbage collection works. It will make the script run subjectively "faster". -D stands for debug mode.

P.P.S. And pretend you're working on a Sinclair. :D

P.P.P.S. You may try to enter a "string" like this: '"this is a multiword string with spaces" (mind the leading apostrophe!). It will go into the hash table as SYMBOL though, so I don't know yet if it is of any use anywhere but a (print) statement. :(
Title: Re: Lisp in Basic
Post by: RobbeK on August 18, 2014, 01:40:25 PM
Thanks Mike,  !!   (4 the tips)

(quit)  ok !      yes, i have the pdf -- but only tried the classics     (bye) (by) & (exit)   ???

Sinclair --   well , I had the ZX-81 and the QL  (and answering Aurel's question , they had a Lisp, but it was not written in Basic )

best , Rob
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 01:59:41 PM
Bitbucket (https://bitbucket.org/ScriptBasic/sblisp) updated with Mike's current SBLisp.

@Rob - If you ever get bored with us, here is something to ponder. LispOS (http://losak.sourceforge.net/)  :o

(http://a.fsdn.com/con/app/proj/losak/screenshots/9377.jpg)
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 02:26:20 PM
Not here.  :-\

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb Xblisp002.txt
SBLisp - Scheme BASIC Lisp

(define divisor?
  (lambda (p q)
ERROR: Read.
ERROR: Problem in file Xblisp002.txt
ERROR: Bad type.
0]

Looks the same with my version before Mike's changes.

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp_gold.sb Xblisp002.txt
SBLisp - Scheme BASIC Lisp

(define divisor?
  (lambda (p q)
ERROR: Read.
ERROR: Problem in file Xblisp002.txt
0]
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 02:52:00 PM
 :o !

Are you absolutely sure you haven't changed a single line in my script? Are you absolutely sure you haven't tried to merge some of your untested mods with my script?

Please try to compile a 32-bit SBLisp.exe from my verbatim source and see what happens in your Windows and/or Wine.

I have absolutely no PB here (my file was just renamed to rob2.lisp):

(going to check it in WoW64 under my Win 7 now... rebooting...)

.
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 02:57:39 PM
I'm using your copy of SBLisp and even tried it with my old version. (see above) You can verify what I'm running by the source on Bitbucket.

Runs fine under Wine.

Code: [Select]
SBLISP
------

LIST=(2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
297 298 299)

FILTERING_PRIMES_BY_MAPPING
(2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 0 0 0 0 53 0 0 0 0 0 59 0 61 0 0 0 0 0 67 0 0 0 71 0 73 0 0 0 0 0 79 0 0 0
 83 0 0 0 0 0 89 0 0 0 0 0 0 0 97 0 0 0 101 0 103 0 0 0 107 0 109 0 0 0 113 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0 0 0 131 0 0 0 0 0 137 0 139 0 0 0 0 0 0 0 0 0 149 0 151 0 0 0 0 0 157 0
0 0 0 0 163 0 0 0 167 0 0 0 0 0 173 0 0 0 0 0 179 0 181 0 0 0 0 0 0 0 0 0 191 0 193 0 0 0 197 0 199 0 0 0 0 0 0 0 0 0 0 0 211 0 0 0 0 0 0 0 0 0 0 0 223 0 0 0 227 0 229 0 0 0 233 0
0 0 0 0 239 0 241 0 0 0 0 0 0 0 0 0 251 0 0 0 0 0 257 0 0 0 0 0 263 0 0 0 0 0 269 0 271 0 0 0 0 0 277 0 0 0 281 0 283 0 0 0 0 0 0 0 0 0 293 0 0 0 0 0 0)
....FINISHED..........
T
0]
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 03:07:32 PM
John,

I confirm it runs perfectly fine for me with both 32-bit scriba.exe and 64-bit sb64.exe under Windows 7.

Please find the initialization of flag badluck = 666 and change it to, say, badluck = 100 and see if it works in Linux...
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 03:17:18 PM
Quote from: mike
Please find the initialization of flag badluck = 666 and change it to, say, badluck = 100 and see if it works in Linux...

That's cruel!  :-[

Did I forget to mention how happy I am with the color syntax highlight with Ultra Edit on Linux?   ;D

Seriously. I have a solution so you can try this. I will copy the current SBLisp to Koding.com (Ubuntu 64 bit) and you can see it for yourself. If you don't have a FREE account already, (no info other than a valid e-mail needed) than I will send you my login info.

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 03:36:04 PM
Back to XP (I have so many more useful tools installed here...)

WinMerge shows absolutely no difference between my script and the repo except i) mine has double quotes around error.bas and ii) mine has Windows standard 0xD+0xA line breaks against 0xA-only Linux linefeeds in the repo. But it should be normal as it was me that saved the respective files in that way.

Hmmmm... Tell me please if you can compile me a standalone executable 32-bit scriba file without non-system dependencies or config file for Linux? I prefer to work offline. If yes then where and how should I put it to be able to run lisp.sb in my local Linux installations?

Now please try to load Rob's file manually. Start scriba lisp.sb then manually type in (load 'Xblisp002.txt) to see what happens. Also be forewarned, hehe again, that Rob's file has Windows linebreaks in it.

Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 03:38:19 PM
I have a Ubuntu 32 bit VirtualBox I could try it in.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 03:44:44 PM
Please do. Can you both compile and try or try only? (be sure to read my previous message with mods)
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 03:46:00 PM
Nope. Doesn't work on Ubuntu 32 bit either.

Code: [Select]
jrs@U32VB:~/sb22/sblisp$ ../bin/scriba lisp.sb Xblisp002.txt
SBLisp - Scheme BASIC Lisp

(define divisor?
  (lambda (p q)
ERROR: Read.
ERROR: Problem in file Xblisp002.txt
ERROR: Bad type.
0]

FWIW - (fibonacci 24) works on Ubuntu 64 bit.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 03:46:59 PM
I still see no response to my note on Windows line breaks. Please read my previous message but one now.
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 03:58:33 PM
Run after changing Rob file to Linux linefeed only termination. (Ubuntu 32 bit)

Code: [Select]
jrs@U32VB:~/sb22/sblisp$ ../bin/scriba lisp.sb Xblisp002.txt
SBLisp - Scheme BASIC Lisp

(define divisor?
  (lambda (p q)
ERROR: Read.
ERROR: Problem in file Xblisp002.txt
ERROR: Bad type.
0](quit)
jrs@U32VB:~/sb22/sblisp$

Here is running the same but SBLisp as a standalone.

Code: [Select]
jrs@U32VB:~/sb22/sblisp$ ./SBLisp Xblisp002.txt
SBLisp - Scheme BASIC Lisp

(define divisor?
  (lambda (p q)
ERROR: Read.
ERROR: Problem in file Xblisp002.txt
ERROR: Bad type.
0]
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 04:03:39 PM
OK John,

Please where can I download precompiled 32- and 64-bit SB distros for Linux so I don't have to pull in all the dependencies and compile SB from the sources myself?
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 04:08:27 PM
From the Script BASIC forum 2.2 beta release sticky on the download board.

Here is the link (http://www.scriptbasic.org/forum/index.php/topic,291.0.html)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 04:11:06 PM
Thank you John,

I'll come back later when I have anything to say. :)
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 04:11:58 PM
Thanks Mike for going the extra mile!
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 06:52:21 PM
Hello John,

Your (fibonacci 20) worked only because it was a Linux file that you typed in yourself (remember (( n 2) typos?). Therefore there were never any Windoze carriage returns in there. Rob's file was originally Windoze and you failed to re-save it without CR's as I asked you to. You have to have a special editor that has this capability as an explicit feature to select. Otherwise mere re-saving it under Linux doesn't remove the CR's.

So the problem was in CHOMP(). Its behavior under Linux and Windows is different. It chomps full CRLF's under Windows but only LF's under Linux leaving CR's in place. Linuxoid TRIM() doesn't trim Windoze CR's either. It isn't important in the interactive mode where only the respective symbols are generated in response to Enter but it's a killer in the file load mode.

I fixed this bug and now SBLisp can swallow any line endings in both worlds. I also made use of your -D flag to add a couple special printouts to the ERROR cases. Thanks for that option, it's gonna be useful in the future.

So have a look at the picture and test the new lisp.sb then upload it to the repo, please.

(beware: now that you've got me hooked on Linux and are playing truant, you may easily lose your leading place in the acknowledgment blurb, hehe...)

.
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 07:09:10 PM
I'm glad it wasn't a SB thing. I deal with the MS/Linux line terminator and \/ issue all the time.

I'm glad you're liking Linux again.

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb Xblisp002.txt
SBLisp - Scheme BASIC Lisp

(define divisor?
  (lambda (p q)
   (let (( x (/ p q)))
     (if (= x (floor x)) 1 0 ))))
DIVISOR?
(define more-divisorsx
  (lambda ( i x nr)
    (if (or (> i (/ x 2)) (> nr 0 ) ) nr
      (more-divisorsx (+ i 1) x (+ nr (divisor? x i))))))
MORE-DIVISORSX
(define more-divisors
  (lambda (x)
   (more-divisorsx 2 x 0)))
MORE-DIVISORS
(define prime?
   (lambda (x)
     (if (= (more-divisors x) 0 ) x 0 )))
PRIME?
(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))
MAKE-LISTX
(define make-list
     (lambda (x)
      (reverse (make-listx 2 x '() ))))
MAKE-LIST
(define sq (make-list 300))
SQ
(define main
  (lambda ()
    (newline)
    (newline)
    (newline)
    (newline)
    (print 'SBLisp ) (newline)
    (print '------ ) (newline) (newline)
    (print 'List= )
    (print sq)
    (newline)
    (newline)
    (print 'Filtering_primes_by_mapping)
    (newline)
    (let (( res (map prime? sq)))
      (print res)
      (newline)
      (print '....finished )
      (print '..... )
)))
MAIN
(main)




SBLISP
------

LIST=(2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299)

FILTERING_PRIMES_BY_MAPPING
(2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 0 0 0 0 53 0 0 0 0 0 59 0 61 0 0 0 0 0 67 0 0 0 71 0 73 0 0 0 0 0 79 0 0 0 83 0 0 0 0 0 89 0 0 0 0 0 0 0 97 0 0 0 101 0 103 0 0 0 107 0 109 0 0 0 113 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0 0 0 131 0 0 0 0 0 137 0 139 0 0 0 0 0 0 0 0 0 149 0 151 0 0 0 0 0 157 0 0 0 0 0 163 0 0 0 167 0 0 0 0 0 173 0 0 0 0 0 179 0 181 0 0 0 0 0 0 0 0 0 191 0 193 0 0 0 197 0 199 0 0 0 0 0 0 0 0 0 0 0 211 0 0 0 0 0 0 0 0 0 0 0 223 0 0 0 227 0 229 0 0 0 233 0 0 0 0 0 239 0 241 0 0 0 0 0 0 0 0 0 251 0 0 0 0 0 257 0 0 0 0 0 263 0 0 0 0 0 269 0 271 0 0 0 0 0 277 0 0 0 281 0 283 0 0 0 0 0 0 0 0 0 293 0 0 0 0 0 0)
....FINISHED..........
T
0]

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 18, 2014, 07:24:31 PM
I'm glad it wasn't a SB thing.
But it is! Actually it's a design fault! Why don't I have to think about where my files come from? And why my TRIM() would chomp and trim everything that's whitespace no matter where it comes from -- Windows, Unix, or Mac?!

Stop being chauvinistic, John, and if you have time, spend it on fixing the SB sources to forget about your linebreak headaches once and for all.

Glad to see it working on your machine. Means I didn't spend yet another sleepless night for nothing. :)
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 07:27:23 PM
Thanks Mike for tracking down the issue.

Quote from: Mike
beware: now that you've got me hooked on Linux and are playing truant, you may easily lose your leading place in the acknowledgment blurb, hehe...

Don't complain. You're getting major action in the commit comments.  :P
Title: Re: Lisp in Basic
Post by: JRS on August 18, 2014, 11:57:07 PM
Hey Mike,

That Windows 7 looking Linux you're using is pretty slick!

Here is Debian noroot (http://sourceforge.net/projects/libsdl-android/) running on my Samsung Galaxy  Tab 2 10.1 tablet. This is the best version of Linux running on Android so far. No VNC as X11 is done in SDL. I was able to get Script BASIC to compile native ARM from source but realized I didn't use the source we tweaked for the Android Linux (ARM) version. I'll recompile tomorrow with the correct source.




.
Title: Re: Lisp in Basic
Post by: RobbeK on August 19, 2014, 12:01:36 AM
A big "step"

step is the perfect word for this.
I could set up (range x) for the lib (the idea comes from Racket Scheme).
This is the mother of iteration ....

see source ,   can do (newlines x) now , if it were iterative ...

best Rob

(oops, yes , I use LispIDE for building the source -- it gives matching paren's , is this a problem ??)

.
Title: Re: Lisp in Basic
Post by: JRS on August 19, 2014, 12:06:59 AM
Xblisp003.txt
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb Xblisp003.txt
SBLisp - Scheme BASIC Lisp

(define divisor?
  (lambda (p q)
   (let (( x (/ p q)))
     (if (= x (floor x)) 1 0 ))))
DIVISOR?
(define more-divisorsx
  (lambda ( i x nr)
    (if (or (> i (/ x 2)) (> nr 0 ) ) nr
      (more-divisorsx (+ i 1) x (+ nr (divisor? x i))))))
MORE-DIVISORSX
(define more-divisors
  (lambda (x)
   (more-divisorsx 2 x 0)))
MORE-DIVISORS
(define prime?
   (lambda (x)
     (if (= (more-divisors x) 0 ) x 0 )))
PRIME?
(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))
MAKE-LISTX
(define make-list
     (lambda (x)
      (reverse (make-listx 2 x '() ))))
MAKE-LIST
(define range
  (lambda (x)
    (reverse (make-listx 0 x '() ))))
RANGE
(define newlines
  (lambda (x)
    (map newline (range x))
      'ok ))
NEWLINES
(define sq (make-list 200))
SQ
(define main
  (lambda ()
    (newlines 10)
    (newline)
    (print 'SBLisp ) (newline)
    (print '------ ) (newline) (newline)
    (print 'List= )
    (print sq)
    (newline)
    (newline)
    (print '"Filtering primes by mapping")
    (newline)
    (let (( res (map prime? sq)))
      (print res)
      (newline)
      (print '....finished )
      (print '..... )
)))
MAIN
(main)











SBLISP
------

LIST=(2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199)

FILTERING PRIMES BY MAPPING
(2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 0 0 0 0 53 0 0 0 0 0 59 0 61 0 0 0 0 0 67 0 0 0 71 0 73 0 0 0 0 0 79 0 0 0 83 0 0 0 0 0 89 0 0 0 0 0 0 0 97 0 0 0 101 0 103 0 0 0 107 0 109 0 0 0 113 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0 0 0 131 0 0 0 0 0 137 0 139 0 0 0 0 0 0 0 0 0 149 0 151 0 0 0 0 0 157 0 0 0 0 0 163 0 0 0 167 0 0 0 0 0 173 0 0 0 0 0 179 0 181 0 0 0 0 0 0 0 0 0 191 0 193 0 0 0 197 0 199)
....FINISHED..........
T
0]


Nice to see this thing actually working.  8)
Title: Re: Lisp in Basic
Post by: RobbeK on August 19, 2014, 12:59:35 AM
Et voilà , messieurs ... 

...   the "iterator"   

the operator must be quoted !!     like     (iterate 'newline 5)    8)

best Rob

oops, yes ..  the source is it QB ??  -- can't you wring/wrench it through something as QB64 / FB to give it more speed ??
(now filtering the zero's -- then I'm off (probably) till this evening

.
Title: Re: Lisp in Basic
Post by: RobbeK on August 19, 2014, 01:29:28 AM
With zero removal and the "glorious  iterator" in action ...   8)

-----------------

(define divisor?
  (lambda (p q)
   (let (( x (/ p q)))
     (if (= x (floor x)) 1 0 ))))


(define more-divisorsx
  (lambda ( i x nr)
    (if (or (> i (/ x 2)) (> nr 0 ) ) nr
      (more-divisorsx (+ i 1) x (+ nr (divisor? x i))))))

(define more-divisors
  (lambda (x)
   (more-divisorsx 2 x 0)))

(define prime?
   (lambda (x)
     (if (= (more-divisors x) 0 ) x 0 )))

(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))

(define make-list
     (lambda (x)
      (reverse (make-listx 2 x '() ))))

(define range
  (lambda (x)
    (reverse (make-listx 0 x '() ))))

(define sq (make-list 200))

(define iterate
  (lambda (op it)
    (map (eval op) (range it))
  T ))

(define filter-zeroesx
   (lambda (L M)
     (if (= (length L) 0) M
         (if (> (car L) 0 ) (filter-zeroesx (cdr L) (cons (car L) M))
                            (filter-zeroesx (cdr L) M )))))

(define filter-zeroes
    (lambda (L)
      (filter-zeroesx L '() )))


(define main
  (lambda ()
    (iterate 'newline 10)
    (newline)
    (print 'SBLisp ) (newline)
    (print '------ ) (newline) (newline)
    (print 'List= )
    (print sq)
    (newline)
    (newline)
    (print '"Filtering primes by mapping")
    (newline)
    (let (( res (map prime? sq)))
      (print res)
      (iterate 'newline 3)
      (print '"Removing the zeroes") (newline)
      (print (reverse (filter-zeroes res)))
      (newline)
      (print '....finished )
      (print '..... )
)))

(main)

-------------------------------

best , Rob ...  the (reverse ..  )   because it are all FILO operations ...   first in - last out
addendum -- added 006 which does proper printing too.
Is it auto-GC , or do I have to code it ????

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 19, 2014, 03:26:59 AM
Hi Rob,

Et voilà , messieurs ...  ...   the "iterator"
.............................................
addendum -- added 006 which does proper printing too.
Your achievements are simply amazing! I can't wait to see the ASCII Mandelbrot running in my XBLisp console too. :D

Quote
Nice to see this thing actually working.  8)
Thank you for your kind words. My eagerness to go on with this project has doubled now that you're emitting usable code for it. :)

Quote
the source is it QB ??  -- can't you wring/wrench it through something as QB64 / FB to give it more speed ??
The (inoperative) original was written in QB4.5. But having it as yet another standalone LISP is not the main goal of this project. The milestones are:

1. To maintain a common code development base compatible with at least 3 languages -- ScriptBASIC, FBSL, and OxygenBasic for as long as it is possible and reasonable;

2. To enrich the vocabulary to maximum compatibility with a standard Scheme dialog of LISP;

3. Finally, split the project into 3 distinct language branches and convert it to CBASIC for SB, and DynC, for FBSL. This will allow these two languages to have XBLisp running much much faster in native machine code. But this will also make the branches totally source code incompatible. Note that the O2 project branch currently named OxyLISP runs in fast JIT compiled machine code already now. But it is still having serious issues due to strong typification of its data. SB and FBSL don't have such issues due to their variant-based variables.

Yes, XBLisp is currently very slow but it is very convenient for development. Once XBLisp is re-written in CBASIC, DynC and usable O2, the LISP code will run anywhere between 200 to 500 times faster. In this way, each one of SB, FBSL, and O2 will have its own fast and practical LISP module.

Isn't that challenging as it is? :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 19, 2014, 03:42:41 AM
Hi John,

Don't complain. You're getting major action in the commit comments.  :P
... which doesn't however justify your adultery with ECL in the meantime. :P

Quote
Here is Debian noroot running on my Samsung Galaxy  Tab 2 10.1 tablet.
Looks nice and very Linux-like. :) 

Gedit has standard built-in syntax highlighting themes for VB.NET and Scheme under my Win 7 styled Ubuntu LTS that you're seeing in my screenshot. They're working perfectly well for our SB/FBSL/O2 BASIC code and XBLisp scripts too.

(proceeding with the remaining GoSub to Function conversion as planned)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 19, 2014, 03:59:44 AM
Hello Rob,

A practical question to you. Is it natural for any LISP to see the source code of a program being outputted to the console while the program loads from a disk file?

If not then I can make it so that it would go to the console only in the -D mode. The normal mode will print only the output of the program. The interactive mode will stay unchanged.

Do you think this would be reasonable and natural for a LISP user?
Title: Re: Lisp in Basic
Post by: RobbeK on August 19, 2014, 04:30:52 AM
Hi Mike,

The CL's (I think all of them) give the definition-names while loading , but not the bodies.
NewLisp also gives the bodies, but it has (silent .... ) if included in the source then it outputs nothing to the console.
Don't know about BigLoo (all my code was compiled from within a seperate console window, not the REPL ).

It has of course the advantage that when there's something wrong with the source it will indicate where ... (?) .. but then, on an error there should always be a kind of indication what/where 's happening.

best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 19, 2014, 04:40:24 AM
Rob,

Quote
Is it auto-GC , or do I have to code it ????

It does automatic garbage collection all by itself. You can see it with your own eyes if you use the following command line to load your scripts using scriba.exe:

scriba.exe lisp.sb Xblisp006.txt -d

-d means "debug mode" in which you can see GC work.

Be sure to load the latest lisp.sb script (https://bitbucket.org/ScriptBasic/sblisp/src/69bc08d824b14939ff82d99aae4bc39904ab5804/lisp.sb?at=master) from the repository!

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 19, 2014, 05:43:59 AM
Rob,

Quote
it has (silent .... ) if included in the source then it outputs nothing to the console.
I like this very much. What do the periods .... here stand for? Can you give an example, please?

Quote
on an error there should always be a kind of indication what/where 's happening
That's exactly what's there in XBLisp now. Error reports are always active but if e.g. a file with an illegal line break character is being loaded in a usual way, then the report will look like the following:

ERROR: Read.
ERROR: Problem in file Xblisp002.txt
ERROR: Bad type.


OTOH when the same happens with a -d debug mode switch, then the report will be more informative:

ERROR: Read.
ERROR: Problem in file Xblisp002.txt
ERROR: Faulty line #2: '  (lambda (p q)'
ERROR: Bad type in SetCar: ptype=-1


And I'm planning to add many more detailed debug messages in the future.

Will you approve of such a scheme coupled with the (silent ....) directive added to the XBLisp vocabulary?


Title: Re: Lisp in Basic
Post by: JRS on August 19, 2014, 06:06:39 AM
Mike,

What FUNCTION/SUB routines at this point would be better served by a Script BASIC C BASIC conversion to an extension module call? It would be nice to know the top 10 routines that are used most and are candidates for a conversion.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 19, 2014, 06:33:19 AM
Hi John,

You're indeed an early bird! Is it really 6:30 a.m. at your place? :D

Currently, XBLisp has no way of sharing memory with anyone. So for the moment the only two feasible functions in an SB:SBLisp interface on the SB side of it IMO would be SBL_StartInteractiveSession() and SBL_LoadLispFromFile(filename$). The functions should return when the respective interactive/file exec sessions are over.

Note that if the SBLisp file to execute doesn't contain a (quit) command, then the file exec session will be followed by an interactive spell until the user enters a command to quit.

The entire SBLisp should (and I think will) be finally rewritten in CBASIC, i.e. in ANSI C similar to FBSL's DynC. It will become feasible as soon as there are no more GoSub's left in XBLisp.

P.S. Or we can also add SBL_LoadLispFromMemory(stringtoload$) functionality easily on the XBLisp side of the interface and provide this function on the SB side of it.
Title: Re: Lisp in Basic
Post by: JRS on August 19, 2014, 06:50:23 AM
Quote
P.S. Or we can also add SBL_LoadLispFromMemory(stringtoload$) functionality easily on the XBLisp side of the interface and provide this function on the SB/FBSL side of it.

I think that is a great idea. Please add it!
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 19, 2014, 07:06:58 AM
Can a SB function accept a pointer to an ASCIIZ string as its argument and convert it into a usable SB string?


For example, in FBSL I can write:

CALL FBL_LoadLispFromMemory(POINTEROF "(quit)")

and use it further in the receiver in the following way:

SUB FBL_LoadLispFromMemory(strptr AS LONG)
DIM localstr = PTRTOSTRING(strptr)

...................
END SUB

and here localstr will be a usual FBSL String Variant containing the (quit) string that it has received.
Title: Re: Lisp in Basic
Post by: RobbeK on August 19, 2014, 07:24:49 AM
Hi Mike ,

those ... stand for any thing ...

(silent
   (define x (lambda (...)   ...  ))
   (define message '"this is a message")
   .....
)  ;; end of the silence

'" below this marker the code is not tested - rev . 1.44 : new from (tst)  "     ;; goes to the console

(silent
    (define tst .... )
    .... 
)             ;; ends the silence again

best, Rob
.. probably   (silent)  and (speak)  [without arguments] could be easier mechanisms to code , I think

 
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 19, 2014, 07:28:49 AM
That's cool Rob,

I'll have it implemented in XBLisp shortly.

Thanks for the tip.
Title: Re: Lisp in Basic
Post by: RobbeK on August 19, 2014, 07:47:13 AM
Hi Mike,

the Post Script on my message was (in case it escaped you - i added it after some thinking ) :

. probably   (silent)  and (speak)  [without arguments] could be easier mechanisms to code , I think ..

This mechanism makes excellent communication -- once compiled this will be ignored , but in interpreted mode you can add things like

"should I compile and reload ? "       triggers        (load (compile "this-file.lisp))     8)

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 19, 2014, 07:53:23 AM
Is (speak) used in any LISP dialect?
Title: Re: Lisp in Basic
Post by: JRS on August 19, 2014, 09:28:39 AM
E-mail responses from Arthur.

Quote from: Arthur Nunes-Harwitt
   The reason for the "non-standard" flow is to implement proper tail
calls.  The BASIC code is written in a style similar to assembly
language...  If Script BASIC is properly tail recursive, then it should be
possible to change the code.

  (On errors, I attempt to clear the BASIC subroutine stack manually.)

   I don't have that much time to work on the new implementation, but I can
tell you why I wrote the code the way I did.

   Just make sure you don't break proper tail calling.

   I'll send you some Scheme code that should work without blowing the
stack.

Title: Re: Lisp in Basic
Post by: RobbeK on August 19, 2014, 10:05:17 AM
Mike,

neither (silent) nor (speak) / (talk) is standard  ..  (as many things in NewLisp -- it's Lisp , but it mixes some Common Lisp and Scheme --  and adds some things --  p.e.  (eval-string    )  is very interesting imho (for embedding p.e.)  ).

PicoLisp goes even further away from any standard .. Mr Alexander Burger calls next a gem  -- definition of (mutual?) recursion :

:

(de recur recurse
   (run (cdr recurse)) )

the "de" stands for define/defun


best Rob   
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 19, 2014, 10:33:42 AM
John,

Thanks for the information. You may pass over my response to Mr Nunes-Harwitt in its verbatim form.

QUOTE

There is absolutely no functionality whatsoever implemented in this QB 4.5 code that would allow the *QB program stack* to be restored in case Lisp-in-Basic hits an error while one of its many recursive GoSub's is in deep recursion into itself, its siblings and children, and its parent such as LispPrint or especially LispEval into the bargain.

All that the HandleError: trap actually does is unwind the Lisp code pointer *bsd* to zero in order to preclude any further execution and then point the program flow into a new round of looping within the main program loop LispReadEvalPrintLoop:.

This policy simply ignores the fact that the *QB program stack* near exhausted by previous deep recursion is left absolutely unattended. *(gc)* has nothing to do with the unwinding of *QB program stack* and cannot cure the situation by definition.

QB 4.5 has no mechanisms to reset an exhausted program stack. Standalone or inlined assembly could have stored the initial state of program stack pointer and reset it to the thus stored value whenever a Lisp exception was raised while in deep recursion. But this couldn't be mimiced in QB 4.5 at the time. TurboBasic (may BZ rest in peace) could do it but not its QB counterpart.

That said, the *only* feasible way to resolve this stalemate in QB 4.5 is to set up a global exception flag in the error trap and make all the recursive GoSub's bail out of recursion early. They should be moving up and up the recursion levels clearing their stack frames in a natural manner until the very first nested recrsion level surfaces in the main program loop LispReadEvalPrintLoop: where the exception flag may be safely cleared.

This is exactly how the current SB/FBSL/O2 code behaves thus being incongruously more safe, stack-wise, than its early QB 4.5 prototype.

UNQUOTE


Now John, my nightly recursive GoSub nightmare has turned into a nightmare by day. Almost every other GoSub yet left in LispEval is not only self recursive but it also recurses into pieces of itself. The work is very meticulous and bug prone. So I'm going completely off the air until I'm through.



I hope you won't be feeling overly lonely while I'm away. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 19, 2014, 10:41:59 AM
OK then Rob,

What does standard Scheme do while a program is loading from a disk file?

I do not want to invent my own syntax and vocabulary at this stage. I want to be able to run standard Scheme program solutions e.g. such as those found in the Scheme category on the RosettaCode site (http://rosettacode.org/wiki/Category:Scheme).

Once this is done, we can continue to amuse ourselves with making our XBLisp better and/or more versatile than standard Scheme.

So how does Scheme behave when loading files? (I simply don't have time enough for personal exploration of unknown territories... :) )
Title: Re: Lisp in Basic
Post by: JRS on August 19, 2014, 10:47:05 AM
Quote
I hope you won't be feeling overly lonely while I'm away.

I'll keep the light on while you're away.  :'(

I will send your message to Arthur and CC you on the e-mail.
Title: Re: Lisp in Basic
Post by: RobbeK on August 19, 2014, 01:09:35 PM
Hi Mike,

BigLoo Scheme and CL identical , just the definition names (attached  -- loaded what I posted here today  the pr.scm file ).
In case of an error, both will give more detail where it goes wrong.

.. and if I may , something the true Lisper (the religious type) may not tell you -- those variadic and typeless  - while fantastic and glorious abstractions - have a flip-side :::   speed.  (which is completely logical) 

I did a test now  (attached)
JuliaN  : highest compiler optim. ,   variadic and typeless
Julia    : turned off above  ...     this means I have to declare my variables and things like (+ a b c) do not work any more , it's just (+ a b)   .. finito.. 

best Rob
hoping you see any difference on a faster computer than mine  (that means probably almost every computer  8)  )


 
 

.
Title: Re: Lisp in Basic
Post by: JRS on August 19, 2014, 03:56:25 PM
@Rob

Why are those .exe files so large? Is there stored user data in those files?

Why is GCL / CL (common lisp) and the word HUGE synonymous while doing my discovery?

Back to SBLisp. Can this Ackermann Scheme example be convert to run in the home team Lisp? (SBLisp, FBLisp and maybe O2Lisp)

Code: [Select]
(define (A m n)
    (cond
        ((= m 0) (+ n 1))
        ((= n 0) (A (- m 1) 1))
        (else (A (- m 1) (A m (- n 1))))))


Quote
It may not be immediately obvious that the evaluation of A(m, n) always terminates. However, the recursion is bounded because in each recursive application either m decreases, or m remains the same and n decreases. Each time that n reaches zero, m decreases, so m eventually reaches zero as well. (Expressed more technically, in each case the pair (m, n) decreases in the lexicographic order on pairs, which is a well-ordering, just like the ordering of single non-negative integers; this means one cannot go down in the ordering infinitely many times in succession.) However, when m decreases there is no upper bound on how much n can increase — and it will often increase greatly.

Here is a C BASIC Ackermann example.

Code: [Select]
#include <stdio.h>
#include "cbasic.h"

FUNCTION int ackermann(int m, int n)
BEGIN_FUNCTION
  IF (NOT m) THEN_DO RETURN_FUNCTION(n + 1);
  IF (NOT n) THEN_DO RETURN_FUNCTION(ackermann(m - 1, 1));
  RETURN_FUNCTION(ackermann(m - 1, ackermann(m, n - 1)));
END_FUNCTION

MAIN
BEGIN_FUNCTION
  DIM AS int m, n;
  DEF_FOR (m = 0 TO m <= 4 STEP INCR m)
  BEGIN_FOR
    DEF_FOR (n = 0 TO n < 6 - m STEP INCR n)
    BEGIN_FOR
      PRINT ("A(%d, %d) = %d\n", m, n, ackermann(m, n));
    NEXT
  NEXT
  RETURN_FUNCTION(0);
END_FUNCTION

jrs@laptop:~/C_BASIC/sblisp$ time ./ackermann
A(0, 0) = 1
A(0, 1) = 2
A(0, 2) = 3
A(0, 3) = 4
A(0, 4) = 5
A(0, 5) = 6
A(1, 0) = 2
A(1, 1) = 3
A(1, 2) = 4
A(1, 3) = 5
A(1, 4) = 6
A(2, 0) = 3
A(2, 1) = 5
A(2, 2) = 7
A(2, 3) = 9
A(3, 0) = 5
A(3, 1) = 13
A(3, 2) = 29
A(4, 0) = 13
A(4, 1) = 65533

real   0m3.090s
user   0m3.084s
sys   0m0.000s
jrs@laptop:~/C_BASIC/sblisp$

Caching Hack

Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int m_bits, n_bits;
int *cache;
 
int ackermann(int m, int n)
{
        int idx, res;
        if (!m) return n + 1;
 
        if (n >= 1<<n_bits) {
                printf("%d, %d\n", m, n);
                idx = 0;
        } else {
                idx = (m << n_bits) + n;
                if (cache[idx]) return cache[idx];
        }
 
        if (!n) res = ackermann(m - 1, 1);
        else    res = ackermann(m - 1, ackermann(m, n - 1));
 
        if (idx) cache[idx] = res;
        return res;
}
int main()
{
        int m, n;
 
        m_bits = 3;
        n_bits = 20;  /* can save n values up to 2**20 - 1, that's 1 meg */
        cache = malloc(sizeof(int) * (1 << (m_bits + n_bits)));
        memset(cache, 0, sizeof(int) * (1 << (m_bits + n_bits)));
 
        for (m = 0; m <= 4; m++)
                for (n = 0; n < 6 - m; n++)
                        printf("A(%d, %d) = %d\n", m, n, ackermann(m, n));
 
        return 0;
}

jrs@laptop:~/C_BASIC/sblisp$ time ./anor
A(0, 0) = 1
A(0, 1) = 2
A(0, 2) = 3
A(0, 3) = 4
A(0, 4) = 5
A(0, 5) = 6
A(1, 0) = 2
A(1, 1) = 3
A(1, 2) = 4
A(1, 3) = 5
A(1, 4) = 6
A(2, 0) = 3
A(2, 1) = 5
A(2, 2) = 7
A(2, 3) = 9
A(3, 0) = 5
A(3, 1) = 13
A(3, 2) = 29
A(4, 0) = 13
A(4, 1) = 65533

real   0m0.035s
user   0m0.000s
sys   0m0.036s
jrs@laptop:~/C_BASIC/sblisp$
       
Title: Re: Lisp in Basic
Post by: JRS on August 19, 2014, 11:08:02 PM
Charles,

I was trying to convert the caching hack version of the Ackermann example using your shifts() function. If I can get this to work I'll use the C extension module version of shifts() you wrote.

Code: [Select]
' Script BASIC Ackermann

function shifts(v,p,ar)
  local bp,ba,co,cq,bi,x,y,d
  bp=1
  x=0xffffffff and v
  for co=0 to 31
    ba[co]=0
  next
  for co=0 to 31
    bi=x and bp
    cq=co+p
    if (bi<>0) then
      if ((cq>=0)and(cq<32)) then
        ba[cq]=1
      end if
    end if
    bp = bp + bp
  next
  bp=1
  y=0
  '
  ' SUPPORT FOR ARITHMETIC RIGHT SHIFTS
  '
  d=100
  if (ar) then
    if (x and 0x80000000) then 
      d=31+p
    end if
  end if
  '
  for co=0 to 31
   if ((ba[co]<>0)or(co>=d)) then
      y=y or bp
    end if
    bp = bp + bp
  next
  shifts=y
end function


' PRINT shifts(0x80000000,2),"\n"
' PRINT shifts(-32,-2,1),"\n"
' PRINT shifts(8,-2),"\n"


FUNCTION ackermann(m, n)
  IF NOT m THEN ackermann = n + 1
  IF n >= shifts(1, -n_bits) THEN
    idx = 0
  ELSE
    idx = shifts(m, n_bits) + n
    IF cache[idx] THEN ackermann = cache[idx]
  END IF
  IF NOT n THEN
    res = ackermann(m - 1, 1)
  ELSE
    res = ackermann(m - 1, ackermann(m, n - 1))
  END IF
  IF cache[idx] = res THEN ackermann = res
END FUNCTION

m_bits = 3
n_bits = 20

SPLITA STRING(1048576,"") BY "" TO cache
FOR m = 0 TO 1
  FOR n = 0 TO 3 - m
    PRINT "A(",m," , ",n,") = ", ackermann(m, n),"\n"
  NEXT
NEXT
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 20, 2014, 03:04:48 AM
Hi John,

The non-recursive Ackermann seems an ugly beast. Is there any benefit in porting it?

Oxygen and Lispish Recursive: (untested!)
Code: [Select]
'http://en.wikipedia.org/wiki/Ackermann_function
'
function Ack(sys m,n) as sys
sys t
if m>0 then
  if n>0 then
    t=Ack(m,n-1)
    return Ack(m-1,t) 
  else
    return Ack(m-1,1)
  end if
else
  return n+1
end if
end function

/*

( let ack " m n
  (if (> m 0 )
    (if (> n 0)
      (eval
        (decr m)
        (decr n)
        (let t (ack n 1))
        (ack m t)
      )
      ;else n=0
      (eval
        (decr m)
        (ack m 1)
      )
    )
    ;else m=0
    (+ n 1)
  ) ;end if m>0
")

*/
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 07:54:14 AM
Quote
The non-recursive Ackermann seems an ugly beast. Is there any benefit in porting it?

It seems fast but not sure about the results.  Thanks Charles for the help & code!

FYI   Ack(4,1) gives me a seg. fault.

Code: [Select]
' Ackermann

FUNCTION Ack(m, n)
  IF m > 0 THEN
    IF n > 0 THEN
      t = Ack(m, n - 1)
      Ack = Ack(m - 1, t)
    ELSE
      Ack = Ack(m - 1, 1)
    END IF
  ELSE
    Ack = n + 1
  END IF
END FUNCTION

FOR m = 0 TO 3
  FOR n = 0 TO 3
    PRINT "A(",m,",",n,") = ",Ack(m, n),"\n"
  NEXT
NEXT

jrs@laptop:~/sb/sb22/sblisp$ time scriba ack.sb
A(0,0) = 1
A(0,1) = 2
A(0,2) = 3
A(0,3) = 4
A(1,0) = 2
A(1,1) = 3
A(1,2) = 4
A(1,3) = 5
A(2,0) = 3
A(2,1) = 5
A(2,2) = 7
A(2,3) = 9
A(3,0) = 5
A(3,1) = 13
A(3,2) = 29
A(3,3) = 61

real   0m0.013s
user   0m0.012s
sys   0m0.004s
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 20, 2014, 08:42:44 AM
Hi John,

I can soothe you a little. An attempt to calc (4,1) on any indie interpreter, BASIC or otherwise, will lead to a memory access exception (segfault in Linux lingo) due to the interpreter's process stack exhaustion caused by very deep recursion. The same happens also in FBSL, for that matter. This isn't a specific deficiency in SB but rather a common mischief. One will have to recompile one's interpreter with much larger settings of stack reserve and stack commit options in one's compiler/linker than their usual default values. Interpreters are too stack hungry for their own personal needs.

Secondly, both of your programs are recursive. There's no difference in their Ackermann algo implementation. The only difference between them is a cache used in the native C program to store intermediate calculation results. Each recursion will not go any deeper if the cache already contains the results calculated earlier for particular combinations of m and n values. Avoiding re-recursion would speed up the program significantly. You can see it in your own benchmarks. But this isn't an algorithmic solution, that's simply a hack.

Finally, here's my XBLisp solution using Rob's iterators. It is perhaps clumsy and naive but it calcs up to (3, 2) = 29 in less than a second. An attempt to calc (4,1) will lead to an Out of memory exception in about 15 minutes: ;)

Code: [Select]
;;; Rob's macros

(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))

(define range
  (lambda (x)
    (reverse (make-listx 0 x '() ))))

(define iterate
  (lambda (op it)
    (map (eval op) (range it))
  T ))



;;; ======= My LISP program ======

;; Define iterators
(define m 0)
(define n 0)

;; John's recursive Ackermann algo redefined
(define A
  (lambda (x y)
    (cond
      ((= x 0) (+ y 1))
      ((= y 0) (A (- x 1) 1))
      (else
        (A (- x 1) (A x (- y 1)))
      )
    )
  )
)

;; My Ackermann call
(define Ackermann
  (lambda ()
    (print '"A(") (print m)
      (print '", ") (print n)
        (print '") = ") (print (A m n))
    (newline)
    (set! n (+ n 1))
  )
)

(define for-inner
  (lambda ()
    (set! n 0)
    (iterate 'ackermann (- 6 m))
    (set! m (+ m 1))
  )
)

(define for-outer
  (lambda ()
    (iterate 'for-inner 4)
  )
)

(define main
  (lambda ()
    (iterate 'newline 10)
    (print  '========================== ) (newline)
    (print '"My First XBLisp Program :)") (newline)
    (print  '========================== ) (newline) (newline)
    (for-outer)
  )
)

(main)
(quit)

;;; ==== THAT'S ALL FOLKS! ====



Enjoy! :)

.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 20, 2014, 08:53:34 AM
Ackermann 4,1 also exhausts the stack on o2 code!
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 08:54:09 AM
Damn you're good!

Thanks for the explanation about common stack exhaustion.

Did you know that SB allows GOSUB/GOTO within a FUNCTION/SUB? I know this isn't going to help in the final C based implementation but is a way I could get SBLisp into a MODULE and call it from BASIC.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 20, 2014, 09:07:56 AM
Hi Charles,

It may be an FB problem, not yours. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 20, 2014, 09:14:14 AM
Isn't it a bit extravagant to meet a person with the word "damn"? But "you're good" sure sweetens the pill! :D

Yes John, I'm aware of that and in fact, the old version of SBLisp that's currently in the repo contains a lot of such GoSub's left in SUB LispEval(). I'm still fighting to remove them completely and ensure rock solid bailout of recursion in XBLisp error cases.
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 09:22:10 AM
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ time scriba lisp.sb ackermann.scm
SBLisp - Scheme BASIC Lisp

(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))
MAKE-LISTX
(define range
  (lambda (x)
    (reverse (make-listx 0 x '() ))))
RANGE
(define iterate
  (lambda (op it)
    (map (eval op) (range it))
  T ))
ITERATE
(define m 0)
M
(define n 0)
N
(define A
  (lambda (x y)
    (cond
      ((= x 0) (+ y 1))
      ((= y 0) (A (- x 1) 1))
      (else
        (A (- x 1) (A x (- y 1)))
      )
    )
  )
)
A
(define Ackermann
  (lambda ()
    (print '"A(") (print m)
      (print '", ") (print n)
        (print '") = ") (print (A m n))
    (newline)
    (set! n (+ n 1))
  )
)
ACKERMANN
(define for-inner
  (lambda ()
    (set! n 0)
    (iterate 'ackermann (- 6 m))
    (set! m (+ m 1))
  )
)
FOR-INNER
(define for-outer
  (lambda ()
    (iterate 'for-inner 4)
  )
)
FOR-OUTER
(define main
  (lambda ()
    (iterate 'newline 4)
    (print  '=================== ) (newline)
    (print  '"Ackermann - SBLisp") (newline)
    (print  '=================== ) (newline) (newline)
    (for-outer)
  )
)
MAIN
(main)




===================
ACKERMANN - SBLISP
===================

A(0, 0) = 1
A(0, 1) = 2
A(0, 2) = 3
A(0, 3) = 4
A(0, 4) = 5
A(0, 5) = 6
A(1, 0) = 2
A(1, 1) = 3
A(1, 2) = 4
A(1, 3) = 5
A(1, 4) = 6
A(2, 0) = 3
A(2, 1) = 5
A(2, 2) = 7
A(2, 3) = 9
A(3, 0) = 5
A(3, 1) = 13
A(3, 2) = 29
T
(quit)

real 0m1.133s
user 0m1.116s
sys 0m0.012s
jrs@laptop:~/sb/sb22/sblisp$

Thank You  !!!
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 20, 2014, 09:27:16 AM
Don't mention it, John,

It was my pleasure to see it working in my console too. :)

My PC is just a bit faster so I'm getting some .925 sec or so. That's practically equal.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 20, 2014, 10:16:32 AM
It takes FBSL's DynC almost 18 seconds to calc (4, 1)... :(

But the good thing is it doesn't exhaust the stack though.  ???

.
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 10:37:16 AM
Seems that C is a bit more forgiving.  8)
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 10:40:10 AM
Quote from: Arthur
Dear John,

> Mike Wrote:
>
> There is absolutely no functionality whatsoever implemented in this QB
> 4.5 code that would allow the *QB program stack* to be restored in case
> Lisp-in-Basic hits an error while one of its many recursive GoSub's is
> in deep recursion into itself, its siblings and children, and its parent
> such as LispPrint or especially LispEval into the bargain.

Ah, but there is: return.  If you look for the label ClearStackLoop in the
original code, you'll see that it repeatedly returns.  That is the point,
to clear the stack.  The variable BSD stands for Basic Stack Depth.

-Arthur



==============================================================
Arthur Nunes-Harwitt
Computer Science Department, Rochester Institute of Technology
Title: Re: Lisp in Basic
Post by: RobbeK on August 20, 2014, 01:07:48 PM
Hi all,

FWIIW  -- the GCL compiler gives the message it converted the recursion (the Ackerman) into iterations.

Added a few useful (?) macro's ..  and seq (seq 6)  -> ( 1 ... 6) while range does (0 ... 5)  -- normal Lisp indexbase 0.
(this is important when using the sequence as the number of "iterations" of a certain function )   -- i mean, you can not 0 times iterate something :  in this case it results in 1/0 ::)
example attached :  (as an example , because by memoizing a previous result this can be speeded up a very lot - the sequences are recalculated every time ).

----------------------------------------------------------

(define 1+
   (lambda (x) (+ 1 x)))

(define 1-
   (lambda (x) (- x 1)))

(define println
   (lambda (s)
     (print s) (newline)))


(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))

(define range
  (lambda (x)
    (reverse (make-listx 0 x '() ))))

(define iterate
  (lambda (op it)
    (map (eval op) (range it))
  T ))


(define seq
    (lambda (x)
      (reverse (make-listx 1  (1+ x) '() ))))

;;----------------------------tests -- remove from macro.scm


(define 3eta-1
   (lambda (x)
     (apply + (map (lambda (x) (/ 1 x)) (seq x)))))

(define print3
   (lambda (x)
     (print (3eta-1 x))
     (newline)))

(define tst
   (lambda (x)
     (map print3 (seq x)) T ))

(define main
(lambda()
(iterate 'newline 10)
(println '"First 50 iterations of Zeta(1)")
(println '"-------------------------------")
(println '" ")
(println '"without memoizing things !")
(newline)
(tst 50)
(newline)
(println '"........finished.........")
))

(main)
--------------------------------------------------------------------------------------------------------

best, Rob   
--  forgot, thanks for the LispOS link, John  -- unaware about it


 
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 01:14:24 PM
Thanks Rob!

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ time scriba lisp.sb rob_zeta.scm
SBLisp - Scheme BASIC Lisp

(define 1+
   (lambda (x) (+ 1 x)))
1+
(define 1-
   (lambda (x) (- x 1)))
1-
(define println
   (lambda (s)
     (print s) (newline)))
PRINTLN
(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))
MAKE-LISTX
(define range
  (lambda (x)
    (reverse (make-listx 0 x '() ))))
RANGE
(define iterate
  (lambda (op it)
    (map (eval op) (range it))
  T ))
ITERATE
(define seq
    (lambda (x)
      (reverse (make-listx 1  (1+ x) '() ))))
SEQ
(define 3eta-1
   (lambda (x)
     (apply + (map (lambda (x) (/ 1 x)) (seq x)))))
3ETA-1
(define print3
   (lambda (x)
     (print (3eta-1 x))
     (newline)))
PRINT3
(define tst
   (lambda (x)
     (map print3 (seq x)) T ))
TST
(define main
(lambda()
(iterate 'newline 10)
(println '"First 50 iterations of Zeta(1)")
(println '"-------------------------------")
(println '" ")
(println '"without memoizing things !")
(newline)
(tst 50)
(newline)
(println '"........finished.........")
))
MAIN
(main)










FIRST 50 ITERATIONS OF ZETA(1)
-------------------------------
 
WITHOUT MEMOIZING THINGS !

1
1.500000
1.833333
2.083333
2.283333
2.450000
2.592857
2.717857
2.828968
2.928968
3.019877
3.103211
3.180134
3.251562
3.318229
3.380729
3.439553
3.495108
3.547740
3.597740
3.645359
3.690813
3.734292
3.775958
3.815958
3.854420
3.891457
3.927171
3.961654
3.994987
4.027245
4.058495
4.088798
4.118210
4.146781
4.174559
4.201586
4.227902
4.253543
4.278543
4.302933
4.326743
4.349999
4.372726
4.394948
4.416687
4.437964
4.458797
4.479205
4.499205

........FINISHED.........
T
(quit)

real 0m2.505s
user 0m2.468s
sys 0m0.028s
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 03:01:41 PM
Message sent with images.

Arthur has a link to this thread. His contribution and well as yours is much appreciated.

Thanks to all that have found time to move this along.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 20, 2014, 03:37:19 PM
Too bad.

I have just deleted both messages.

I was wrong. His scheme would, and actually does, work. In QuickBasic, that is; actually impossible to mimic this behavior with the existing vocabulary in SB, FBSL, or any other interpreter that I know of. We would have to open the hoods and get our hands dirty with our engines because this functionality can only be implemented at the underlying C level.

I am so sorry to have been so damn blind, dumb, hard-nosed, and so mouthy at that.  :-[

Shame on me. Please let Mr Arthur Nunes-Harwitt know that I'm hereby withdrawing all my ungrounded criticisms and apologize for my big mouth.


P.S. This doesn't however change our own plan in the least. Orderly bailout from recursive functions in response to a global flag is our only choice. We haven't got anything that would behave like RETURN Label in our environments.
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 03:47:24 PM
While you're in that sensitive mood, why do you think SB is unable to support the stack handling under the covers with GOTO to another GOSUB and have it return? All Arthur did was shave off an extra return and expand his existing GOSUB routine. If I'm wrong, I'm more than willing to invest the time to understand what is truly going on and if it is a problem in SB. From what I'm seeing SBLisp works.

On the other hand we agreed that the end goal was to create a C extension of this in our respective languages. Without the work that you and I have done, SBLisp is a console mode Scheme interpretor which could be used as a learning tool for Lisp. I don't see it being a contender to a real Lisp in it's current form. Once an extension module in C is accomplished, that's when the game changes.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 20, 2014, 04:29:13 PM
John,

XBLisp is currently working perfectly stable because the global flag and emergency returns have been already fully implemented. The GoSub's yet remaining in LispEval also obey this flag and use EXIT SUB instead of RETURN to exit from their LispEval parent to the main loop. It is already working, and note also that we are talking about exception conditions that occur very seldom in our yet non-existent programs.

My proxy dispute with Arthur was somewhat scholastic and pertained to the QB code more than the one we're using now. It doesn't change our plans in the least. And I didn't say we had to add this RETURN Label functionality; we don't need it so urgently. What I really meant was it would be kinda cool to have the same in our interpreters, is all.

Concerning "GOTO to another GOSUB", it wouldn't be a proper vision of the problem. You may not goto to another sub freely while in recursion. For you to have the right to goto, the both ends of the jump must be at the same recursion depth level or the stack will get disbalanced sooner or later, which will end up in an inevitable crash.

It is rather a RETURN deal where the original point (address) of return is substituted with another address one recursion level up the current stack frame. But forget it. This isn't imperatively needed for SBLisp.
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 04:53:54 PM
Will you be releasing something soon?

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 20, 2014, 05:05:59 PM
Tomorrow evening my time (morning, your time). You will have it fasting instead of your usual morning coffee and first smoke. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 20, 2014, 05:11:24 PM
Hmmmm... My Ackermann handcoded in DynAsm is only some 2 seconds faster than DynC. ???

I don't know how it can be seeing John's 3 sec CBASIC benchmark. What optimizations are you using in your stock GCC, John?



@Charles:

Can you somehow comment on these strange phenomena, please?

.
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 05:34:31 PM
Quote
What optimizations are you using in your stock GCC, John?

O3

Looking forward to seeing the new version of SBLisp. Are all the GOSUB/GOTO's gone now?
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 20, 2014, 06:14:36 PM
I confirm Mike's timing with o2 asm. - Time enough to down a cup of jasmine tea, anyway :)

Code: [Select]
function AckA(sys m,n) as sys

return call A m,n

.A
mov ecx,[esp+4] 'm
mov edx,[esp+8] 'n
(
  cmp ecx,0
  jg exit       'm>0 skip
  inc edx       'n+1
  mov eax,edx   'ret n+`
  ret 8
)
(
  cmp edx,0     '
  jg exit       'n>0 skip
  dec ecx       'm-1
  call A ecx,1  'm-1,1
  ret 8
)
dec edx         'm,n-1
call A ecx,edx  't
mov ecx,[esp+4] 'm reload
dec ecx         'm-1
call A ecx,eax  ' m-1, t
ret 8

end function

AckA 4,1 '65533

Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 06:20:14 PM
Quote
Concerning "GOTO to another GOSUB", it wouldn't be a proper vision of the problem. You may not goto to another sub freely while in recursion. For you to have the right to goto, the both ends of the jump must be at the same recursion depth level or the stack will get disbalanced sooner or later, which will end up in an inevitable crash.

I'm confused. Are you speaking of SBLisp's stack or Script BASIC's stack?

Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 06:22:55 PM
Quote
I confirm Mike's timing with o2 asm.

Damn open source source software cheats!  ;D
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 09:33:57 PM
GNU CLISP 2.49 Scratch pad. CompileOnLine.com is running on CentOS (Red Hat clone) 64 bit. Script BASIC is also available there with extension module support. (cURL, SQLite3, ...)


.
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 10:22:52 PM
How would I do this in SBLisp?

Code: [Select]
(loop for i from 1.0 to 3.0 by 0.5 do (print i))

1.0
1.5
2.0
2.5
3.0
Title: Re: Lisp in Basic
Post by: JRS on August 20, 2014, 11:18:09 PM
SBLisp working on CompileOnLine.com.


.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 21, 2014, 01:11:58 AM

Optimised Recursive Ackermann ( o2 asm)

reduces use of stack:

Code: [Select]
function AckB(sys m,n) as sys

mov ecx,m
mov edx,n
return call A

.A
(
  cmp ecx,0
  jg exit       'm>0 skip
  inc edx       'n+1
  mov eax,edx   'ret n+1
  ret
)
(
  cmp edx,0     '
  jg exit       'n>0 skip
  dec ecx       'm-1
  mov edx,1
  call A        'A m-1,1
  ret
)
dec edx         'm,n-1
push ecx        'save m
call A          't
pop ecx         'm reload
dec ecx         'm-1
mov edx,eax
call A          'A m-1, t
ret

end function

AckB 4,1 '65533
Title: Re: Lisp in Basic
Post by: RobbeK on August 21, 2014, 02:23:58 AM
Some more good news ;

Local functions do work

D:\>sblisp
SBLisp - Scheme BASIC Lisp

0](define tst
1]   (lambda (x y)
2]     (let ((f (lambda (x y) (+ x y))))
3]       (f x y))))
TST
0](tst 6 7)
13
0](define tst2
1]  (let ((f (lambda (x y) (+ x y))))
2]   (lambda (x y)
3]    (f x y))))
TST2
0](tst2 5 5)
10
0](tst2 5 56)
61
0] :)

----------------------------------- 
this makes constructions as follows possible

(define max
  (let ((max0 (lambda (x y)
             (if (> x y) x y))))
     (lambda (i L)
       (if (< (length L) 1) i
           (max (max0 i (car L)) (cdr L))))))

-- the primitive is local inside the recursive definiton

but there is more :

 8)

(define variadic
   (lambda (init op L)
      (if (< (length L) 1) init
        (variadic (eval (list op init (car L))) op (cdr L)))))

 ;)

testing
(define max0 (lambda (x y)
             (if (> x y) x y)))
MAX0
(define variadic
   (lambda (init op L)
      (if (< (length L) 1) init
        (variadic (eval (list op init (car L))) op (cdr L)))))
VARIADIC
0](variadic 'max0 '(7 88 8))
ERROR: Too few args.
0](variadic 0 'max0 '(7 88 8))
88
0](variadic 0 'max0 '(7 88 8999))
8999
0](variadic 0 'max0 '(79999 88 8999))
79999
0]

(variadic initial-value operator List)   expands any operator defined with two arguments from left to right over a list !!!

best Rob




 

best Rob 


.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 03:59:58 AM
How would I do this in SBLisp?
Code: [Select]
(loop for i from 1.0 to 3.0 by 0.5 do (print i))

Hi,

Again far from Rob's natural elegance but passable for your immediate needs:

Code: [Select]
; ===================================
;;; Rob's macros
; ===================================
(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))

(define range
  (lambda (x)
    (reverse (make-listx 0 x '() ))))

(define iterate
  (lambda (op it)
    (map (eval op) (range it))
  T ))

(define println
   (lambda (s)
     (print s) (newline)))


; ===================================
;;; My FOR/TO/STEP/EXEC-COMMAND macro
; ===================================
(define iter 0)
(define step 0)
(define comm 0)

(define exec-for
  (lambda ()
    (comm)
    (set! iter (+ iter step))
  )
)

(define for
  (lambda (f u s c)
    (set! iter f) (set! step s) (set! comm c)
    (iterate 'exec-for (floor (+ (/ (- u f) s) 1)))
  )
)
; ===================================

; NB: ITER is the name reserved above for the FOR iterator

(define print-i (lambda () (println iter))) ; define what we want to do
(for 1 3 0.5 print-i) ; do it
Title: Re: Lisp in Basic
Post by: RobbeK on August 21, 2014, 05:06:23 AM
Nice Mike,

I'll work out a much "smarter" iterator ..

we have now
(range . )   indexbase 0
(seq . )  indexbase 1
maybe I should make a generalisation (index start end step) .  .. yep, I'll do this (but keep the range and seq )



0](define n!
1]   (lambda (x)
2]    (apply * (seq x))))
N!
0](n! 5)
120
0] ;)

best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 05:22:35 AM
Hi Rob,

maybe I should make a generalisation (index start end step) .
Great! You'll become John's hero if you do. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 06:04:15 AM
Quote
Concerning "GOTO to another GOSUB", it wouldn't be a proper vision of the problem. You may not goto to another sub freely while in recursion. For you to have the right to goto, the both ends of the jump must be at the same recursion depth level or the stack will get disbalanced sooner or later, which will end up in an inevitable crash.

I'm confused. Are you speaking of SBLisp's stack or Script BASIC's stack?

I'm theorizing out loud. You can't GOTO to a label that expects a GOSUB because you'll eventually hit a RETURN that'll cause a runtime error. Similarly you can't GOSUB into a GOTO label unless it ends up in an END command.

RETURN is a command that exits from the current GOSUB unwinding the process stack of the engine (SB or FBSL or O2, whatever) by one call stack frame, that is by one recursion depth level if recursion is taking place or by one nested call level if the call has been made to another GOSUB label. It then resumes execution from the line that follows the GOSUB line.

QB's RETURN Label implements an interesting functionality that combines two steps in one. First it returns as an ordinary RETURN described above. However it doesn't then resume execution from the line that follows but instead GOTO-es all by itself to the label denoted by Label. Thus you can override the resumption line without giving a damn where it actually is and instead jump to another GOTO label anywhere in the top-level code -- and HandleError is a top-level GOTO label in the QB code of Lisp-in-Basic. And this phenomenon repeats on and on until BSD reaches zero, which means all levels of nesting/recursion have been unwound and the code pointer may safely GOTO to the main loop labeled LispReadEvalPrintLoop.

Does that make sense now?

Until you realize how the QB code really works, you won't be able to reimplement its functionality in full with somewhat different means at hand in SB, FBSL, and O2. You should understand that I'm vocalizing all these things only to keep you informed of what's going on in XBLisp code and why. If I were alone on this project, I would've been doing all my work in complete silence.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 06:17:22 AM
Optimised Recursive Ackermann ( o2 asm)
reduces use of stack:

Bravo Charles!

How could I be so obviously stupid to reload those two registers over and over for nothing? It cost me extra 3.5 seconds spent on nothing! :-[

Thanks a lot for the fix! :)

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 07:07:06 AM
Mesdames et Messieurs ... ... Cached Ackermann in DynC!

Tada-a-a-a-a...!!! ;D

That's a copy-paste of John's ANSI C snippet:

.
Title: Re: Lisp in Basic
Post by: RobbeK on August 21, 2014, 07:38:18 AM
Great! You'll become John's hero if you do  ...

à votre service, Michel  :)   here it is ... the smooth iterator  https://www.youtube.com/watch?v=cA9gUspn6gc

(define make-indexx
     (lambda (i end step m)
      (if (> i end) (reverse m)
          (make-indexx (+ i step) end step (cons i m)))))

(define iterate+
    (lambda (op i end step)
      (map (eval op) (make-indexx i end step '() )) T ))

;; in action /test


0]
0](define g (lambda (x) (println (* x x))))
G
0](iterate+ 'g 1 4 0.5)      ;;;;    operator ,  start , end , step
1
2.250000
4
6.250000
9
12.250000
16
T
0]

(the condition is still true if   index = end  , here 4²  -- keep it or make it >= is false

I will make iterate-  too for the "downsteps"

best, Rob

(pudates always included in the attached macro.scm file   

.
Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 08:09:39 AM
Very cool Rob!

Let me know if you need any help testing the new BASIC interpreter written in SBLisp.  8) ;D
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 08:22:15 AM
Rob,

Your s-mooooooo-th iterator is attractive but:

1. Is your order of operands in iterate+ LISP-specific? I think (iterate varname start stop step (command-to-execute)) would look more natural to me.

2. Is it possible to somehow "name" the iterator variable on the fly from the call? That is, can the following structure be implemented in XBLisp (note that the name of iterator variable i isn't predefined earlier and the name of your s-moo-th iterator here is for):

(for i 1 3 0.5 (println i)) ; I'd like to see this work if possible

If not, perhaps the following would be possible:

(define i 0) ; this would also look natural to me
(for i 1 3 0.5 (println i)) ; I'd like to see this work if possible
Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 08:28:04 AM
A couple standards I would like to purpose.

1. SBLisp scripts use the .sbl attribute.

2. We address Rob going forward as MacRob.  8)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 08:43:44 AM
Standards?!

One more mentioning of SBLisp here and I'll quit. >:( There will be no more updates to the lisp.sb from me and all my further activities will be focused on FBLisp only.

Have you seen me type FBLisp anywhere? Or FBSL and SB, for that matter?

No, it is always XBLisp and SB and FBSL despite my absolute conviction that FBSL is superior to SB in almost anything.

So where's your political correctness?
Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 08:54:12 AM
SBLisp = Scheme BASIC Lisp

.sbl = Scheme BASIC Lisp

@Mike - I thought we already cleared up this pissing contest about SB vs. FBSL and they are two BASIC interpreters with their own strengths and weaknesses. SBLisp is a collative project with 2 and hopefully 3 branches going on at the same time. If this is not your understanding then please clue me in.

I have no problem with you inserting comments into the SBLisp traditional BASIC code indicating SB specific syntax. It might help others porting the code to their preferred BASIC language.

I hope to have an official name for the Script BASIC version of SBLisp but to be honest it wasn't at the top of my bucket list. Please allow me to do my job as the project facilitator so others have the needed resources to do their part.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 21, 2014, 09:00:37 AM
Mike,

With regard to return label, o2 is tolerant of limited stack accumulations within a function, since the stack pointer is restored from the ebp register on exit. This register is unaffected by gosubs

However, the stack may also be explicitly managed thus:

Oxygen
Code: [Select]

'RESTORE STACK POINTER AFTER RECURSIVE GOSUB

function f()
============
sys i
sys fsp=esp 'RECORD STACK POINTER VALUE HERE
gosub sa
return

sa:
while i<10
  i++
  call sa 'BUILD RECURSION
wend
esp=fsp 'RESTORE STACK POINTER (optional!)
goto sb

...

sb:
print "ok"
end function

f()
Title: Re: Lisp in Basic
Post by: Aurel on August 21, 2014, 11:44:45 AM
wait ..wait a little...
this is really to much...
i think that Lisp users on lisp forums don't talk to much about lisp
like some of us here...right?

/oups ...my fault ,,i have started this topic  ::) /

.
Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 12:03:02 PM
And we will be right back after this short Aurel commercial.

Title: Re: Lisp in Basic
Post by: Peter on August 21, 2014, 12:05:28 PM
Cool Aurel,  you have courage.  :)
I hope they do  not bite you!. You started a dangerous attempt.
Title: Re: Lisp in Basic
Post by: RobbeK on August 21, 2014, 12:26:37 PM
Hi all,

@ Mike , it is common to use the operator first as in apply , map , for-each etc.. in recursive based mechanisms , but the NewLisp iterative constructions do it your proposed way   (for (i from to &opt::step)  body)  and (dotimes (i end &opt::break)   body )
so I changed it.

It is still "camouflaged" mapping -- there are no real iterative steps involved -- it just maps a function over a list in one flow - this operation can not be split in parts that give back intermediate results -- there is no way to declare the arguments of the lambda function non-local -- there is no way to define a global variable inside a function (NewLisp can do this)  -- there is no single iterative mechanism to start with that can be expanded ...    but, maybe ...   I have to sleep on it , yes , maybe ...

the operator has to be quoted -- otherwise it will be evaluated before its result is passed as an argument -- if the pseudo-index doesn't need manipulation, it is directly assigned without the need for setting up a local variable for it  (see attached).
..  I also defined  (nth i L) , which gives the nth element of a List (beware indexbase 0)

best I'll read the documentation once again ...



0](iterate+ 1 6 1 '(lambda (x) (println (+ x x)))))
2
4
6
8
10
12
T
0](iterate+ 1 6 1 'println)
1
2
3
4
5
6
T
0](nth 2 (range 6))
2
0](nth 4 (make-indexx 1 10 0.2 '() ))
1.800000
0](make-indexx 1 10 0.2 '() )
(1 1.200000 1.400000 1.600000 1.800000 2.000000 2.200000 2.400000 2.600000 2.800000 3.000000 3.200000 3.400000 3.600000 3.800000 4.000000 4.200000 4.400000 4.600000 4.800000 5.000000 5.200000 5.400000 5.600000 5.800000 6.000000 6.200000 6.400000 6.600000 6.800000 7.000000 7.200000 7.400000 7.600000 7.800000 8.000000 8.200000 8.400000 8.600000 8.800000 9 9.200000 9.400000 9.600000 9.800000 10.000000)
0]

best Rob
(maybe something can be done with pre-declared global variables -- but it looks ugly to define some things for functions/procedures that are pre-coded  -- and I'm even not sure they are correctly assinged in nested lambda-function
(I mean    (lambda (x)
                   (lambda (y)   ....   ))    do x and Y know each other ??   i'll try , but doubt it ...

 @ John  ,  the real story of MacRob - b

The Story of Mac: A Just-So Story
------------------------------------------

Once upon a time, long ago, there was a company of Lisp programmers. It was so long ago, in fact, that Lisp had no macros. Anything that couldn't be defined with a function or done with a special operator had to be written in full every time, which was rather a drag. Unfortunately, the programmers in this company--though brilliant--were also quite lazy. Often in the middle of their programs--when the tedium of writing a bunch of code got to be too much--they would instead write a note describing the code they needed to write at that place in the program. Even more unfortunately, because they were lazy, the programmers also hated to go back and actually write the code described by the notes. Soon the company had a big stack of programs that nobody could run because they were full of notes about code that still needed to be written.

In desperation, the big bosses hired a junior programmer, Mac, whose job was to find the notes, write the required code, and insert it into the program in place of the notes. Mac never ran the programs--they weren't done yet, of course, so he couldn't. But even if they had been completed, Mac wouldn't have known what inputs to feed them. So he just wrote his code based on the contents of the notes and sent it back to the original programmer.

With Mac's help, all the programs were soon completed, and the company made a ton of money selling them--so much money that the company could double the size of its programming staff. But for some reason no one thought to hire anyone to help Mac; soon he was single- handedly assisting several dozen programmers. To avoid spending all his time searching for notes in source code, Mac made a small modification to the compiler the programmers used. Thereafter, whenever the compiler hit a note, it would e-mail him the note and wait for him to e-mail back the replacement code. Unfortunately, even with this change, Mac had a hard time keeping up with the programmers. He worked as carefully as he could, but sometimes-- especially when the notes weren't clear--he would make mistakes.

The programmers noticed, however, that the more precisely they wrote their notes, the more likely it was that Mac would send back correct code. One day, one of the programmers, having a hard time describing in words the code he wanted, included in one of his notes a Lisp program that would generate the code he wanted. That was fine by Mac; he just ran the program and sent the result to the compiler.

The next innovation came when a programmer put a note at the top of one of his programs containing a function definition and a comment that said, "Mac, don't write any code here, but keep this function for later; I'm going to use it in some of my other notes." Other notes in the same program said things such as, "Mac, replace this note with the result of running that other function with the symbols x and y as arguments."

This technique caught on so quickly that within a few days, most programs contained dozens of notes defining functions that were only used by code in other notes. To make it easy for Mac to pick out the notes containing only definitions that didn't require any immediate response, the programmers tagged them with the standard preface: "Definition for Mac, Read Only." This--as the programmers were still quite lazy--was quickly shortened to "DEF. MAC. R/O" and then "DEFMACRO."

Pretty soon, there was no actual English left in the notes for Mac. All he did all day was read and respond to e-mails from the compiler containing DEFMACRO notes and calls to the functions defined in the DEFMACROs. Since the Lisp programs in the notes did all the real work, keeping up with the e-mails was no problem. Mac suddenly had a lot of time on his hands and would sit in his office daydreaming about white-sand beaches, clear blue ocean water, and drinks with little paper umbrellas in them.

Several months later the programmers realized nobody had seen Mac for quite some time. When they went to his office, they found a thin layer of dust over everything, a desk littered with travel brochures for various tropical locations, and the computer off. But the compiler still worked--how could it be? It turned out Mac had made one last change to the compiler: instead of e-mailing notes to Mac, the compiler now saved the functions defined by DEFMACRO notes and ran them when called for by the other notes. The programmers decided there was no reason to tell the big bosses Mac wasn't coming to the office anymore. So to this day, Mac draws a salary and from time to time sends the programmers a postcard from one tropical locale or another.

best Rob
Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 01:37:56 PM
Thanks MacRob for the great story!

Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 03:04:10 PM
Quote
There will be no more updates to the lisp.sb from me and all my further activities will be focused on FBLisp only.

I assume the Bitbucket code is now unfrozen and I can continue on with the current SBLisp source? Thanks for your efforts and advice with the SBLisp project.

I'm going to take a shot at converting what we have now to PowerBASIC PBCC 5. If things don't go smoothly, I will terminate my efforts, leave a note where I left off and what problems I have found.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 06:33:46 PM
Hi Aurel,

/oups ...my fault ,,i have started this topic  ::) /

This is not a fault and you have nothing to be ashamed of here. In fact this is the very first time (and likely also the last) when I am actually greatful to you for starting a thread on a forum. This thread awoke my interest and it actually led me out of stasis and got me working mentally and typematically.


Thank you for that. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 07:09:00 PM
Hi Peter,

Cool Aurel,  you have courage.  :)
I hope they do  not bite you!. You started a dangerous attempt.

Exactly!

The BASIC environment of today is rather acid and only the most poisonous and aggressive entities have survived in it. Many simply went aloft following the natural flow of events in their lives and yet many more mimicked and migrated to other more promising and nourishing pastures.

What you are witnessing here is the genesis of a completely new species that will integrate fission power of modern BASIC with fusion power of modern LISP and become deadly dangerous in a fight. The wars are turning thermonuclear, Peter.

Beware! :D
Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 07:13:21 PM
Mike,

While converting the SBLisp source to PBCC, I noticed in the original QB code that there is TEMP and TEMP$ being used. In the SB conversion this became one variable. I think this needs to be changed. I suggest temp_num and temp_str in the SB code.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 07:34:23 PM
Mr MacRob,

Your fairytale is fantastic! :D

In fact, it is so close to your own current mission in this thread that there's practically nothing fabulous in it. Thank you for co-operation on the XBLisp effort. We need your advice and guidance in so many matters.

If the leading exec operator is a LISP tradition then I am simply discarding John's model

(loop for i from 1.0 to 3.0 by 0.5 do (print i))

as non-canonical LISP. Perhaps it was just another macro invented by someone for the immediate needs of the program.

Quote
which gives the nth element of a List (beware indexbase 0)
I guess we wouldn't be able to recreate the ASCII Mandelbrot code in XBLisp without this operator.

Quote
maybe something can be done with pre-declared global variables -- but it looks ugly to define some things for functions/procedures that are pre-coded
Exactly! I didn't like the three predefined global vars that I used in my (for) solution but I couldn't figure out how I could pass in the variable that the iterator should have used for incrementation.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 07:47:38 PM
I suggest temp_num and temp_str in the SB code.

Occam's Razor (http://en.wikipedia.org/wiki/Occam%27s_razor)

Quote from: Occam's Razor
Entia non sunt multiplicanda praeter necessitatem
(Entities must not be multiplied beyond necessity)

Code reusability is a requirement of good programming practice.
Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 07:56:47 PM
Mike,

To avoid confusion with the name of the proof of concept project, (SBLisp - Scheme BASIC Lisp) and the FBLisp version of the prototype, maybe you can go with what is already established.

FBSL = Freestyle Basic Script Language  & Freestyle Basic Scheme Lisp

Isn't your goal to integrate the two at some point?

I would like to see OxygenBasic be the project language being used in it's traditional BASIC format. At this point it seems that Arthur and I are the only non-Windows users. This started out as nothing more than a personal challenge to convert a sizable QB program to SB. It worked (with your help) and I would have been happy with that. Mr. MacRob getting involved and showing interest in the Lisp is encouraging. I would still like get this into an either a SB BASIC MODULE or a SB C ext. module using C BASIC. Without your input and help, I have better things to do.



Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 08:16:03 PM
Hi Charles,

However, the stack may also be explicitly managed thus:

Congratulations! You've hit the most essential point in the FBSL engine. :D

The entire FBSL is built around this hack: all its vocabulary functions, DynAsm and DynC calls, user-defined functions in FBSL BASIC scripts, calls to all external DLL's follow this save-stack/call/restore-stack pattern.

This way you are allowed to not give a damn whether it is an STDCALL or CDECL function that you're calling because you will never end up with an unbalanced stack. And the overhead of this store/restore toggle is only 2 CPU clocks, which is an infinitessimal by the standards of interpretative environment. These calls are coded in the FBSL sources using GCC's inline assembly.

This however doesn't resolve the task of jumping to a label like in QB's RETURN Label instead of simply resuming execution at the line that follows the call statement. The means for such a jump should be added to the engine itself to immediately retarget the program flow to Label regardless of where the function actually returned to in the script.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 21, 2014, 08:34:50 PM
Hi Mike,

It could be implemented for o2 programs like this:

def RetLabel add esp,4 : goto %1

But for 64 bit code 16 bytes must be added: (stack alignment rules)

def RetLabel add rsp,16 : goto %1

Code: [Select]
def RetLabel add esp,4 : goto %1

sys i
gosub sa
print "ok main"
end

sa:
if i=0 then RetLabel bb
ret

bb:
print "ok bb"



PS: source of Rob's anecdote:
http://www.gigamonkeys.com/book/macros-defining-your-own.html

Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 08:35:16 PM
Mike,

I haven't seen the FBSL version of the SBLisp project since the beginning. What is the current format? Does it look more like the original QB version or the SB version?

Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 08:37:41 PM
Quote
PS: source of Rob's anecdote

Busted! (still a good story)

Quote
Another classic macro-writing macro is once-only,

Code: [Select]
(defmacro do-primes ((var start end) &body body)
  (once-only (start end)
    `(do ((,var (next-prime ,start) (next-prime (1+ ,var))))
         ((> ,var ,end))
       ,@body)))

The SB IMPORT will only include the source once if already reference somewhere else. The SB INCLUDE will include source as many times as the keyword is use. Offloading routines into separate include files may make the code more readable.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 09:04:27 PM
John,

... the name of the proof of concept project ... maybe you can go with what is already established
This is not an established fact to me. Had I considered the repo as the center of this project's activities, I would have confined mine to it. Instead you're seeing me active in this terrifically entertaining thread and you had my assurances that I wasn't even pretending to have my name included in the list of SBLisp acknowledgments.

What I'm trying to do is bring BASIC LISP to the stage where its code is equally usable in three languages. SB is just one of them and, alas, not the strongest one. Therefore I have been doing all my remodeling in the SB dialect of it knowing that if it works in SB then it will also work in the other two. I am deliberately pulling my horses because I have to keep the overall pace in sync with the trailing man in the squad.

You have not yet answered my question here (http://www.oxygenbasic.org/forum/index.php?topic=1147.msg10833#msg10833). It was not a mockery but a practical question. I rarely ask irrelevant questions that I don't need answers to.

Quote
I would like to see OxygenBasic be the project language being used in it's traditional BASIC format.
It will be so as soon as I see the BASIC LISP structure finalized. Then I will be able to select, with Charles assistance of course, the Oxygen means and features most appropriate for the final layout of this project in its BASIC notation.

Quote
I would still like get this into an either a SB BASIC MODULE or a SB C ext. module using C BASIC. Without your input and help, I have better things to do.
With or without your participation, I will have the SB implementation finalized together with the other two. It will be fine with me if then you can make use of my output to the benefit of SB. Neither will it be a tragedy if you can't or wouldn't.

So if there are more urgent matters on your agenda than this fun and entertainment project then you may go ahead right away. It will hardly affect my own plans for this venture.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 21, 2014, 09:14:24 PM

I'm rather concerned that a language enforces the use of recursion, by not supporting iteration and other loops. Cyclical processes are fundamental in this universe, and also in mathematical procedures too :)


Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 09:19:42 PM
It could be implemented for o2 programs like this:

Exactly!

But this isn't possible on the client side of SB and FBSL in their interpetative scripts. This has to be implemented on the server side in their engine's parsers/lexers. Since changes to the SB engine are hardly likely at this point, I'm following the early-exit-on-error pattern that all the three languages will support equally well with their existing functionality.

We haven't yet reached the stage where  the mighty potential of Oxygen's inline assembly will enhance the basic prototype at its most crucial points. :)
Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 09:22:16 PM
Quote
I'm rather concerned that a language enforces the use of recursion, ...

Does this have anything to do with Arthur's warning of not breaking tail recursion?

Quote from: Arthur
If Script BASIC is properly tail recursive, then it should be possible to change the code.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 09:24:18 PM

I'm rather concerned that a language enforces the use of recursion, by not supporting iteration and other loops. Cyclical processes are fundamental in this universe, and also in mathematical procedures too :)

Rob says it is Scheme's most distinctive feature. I wish Mr Nunes-Harwitt had chosen Common Lisp as a model for his Lisp-in-Basic effort. :)
Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 09:30:22 PM
Quote from: Mike
We haven't yet reached the stage where  the mighty potential of Oxygen's inline assembly will enhance the basic prototype at its most crucial points.

I'm not a PowerBASIC user or would I recommend it due to the current state of the company and the unknowns it's users are faced with. On the other hand in it's day, PB was a traditional BASIC standard. I think it would be worth the effort to use PBCC 5 (Classic ?) if nothing more than as an updated QB reference. I'm using the SB source to see how much of the code needs to change to support PB. I almost wish I didn't remove the optional $ symbol in the SB version. The % and other numeric type symbols aren't supported in SB.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 09:57:27 PM
... it would be worth the effort to use PBCC 5 ...
I don't own a PB. I'm out on this project fork.

Quote
nothing more than as an updated QB reference
This is a deadly mistake. QB45 uses variants like SB and FBSL. PB and O2 use strongly typed variables.

Quote
I almost wish I didn't remove the optional $ symbol in the SB version. The % and other numeric type symbols aren't supported in SB.
This won't help you any. BASIC LISP uses common variant arrays to store integer and floating-point numbers. Moreover, it uses its temporary "registers" pvalue, qvalue, etc. to store the same plus strings that go into the hash table at the program initialization stage.

That's why I suspended O2 branch development until we have the current prototype finalized. O2 has the same shortcomings in this respect as your PB. You might as well use O2 for your exercises. (http://www.fbsl.net/phpbb2/images/smilies/icon_m_wallbash.gif)
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 21, 2014, 10:13:38 PM
Quote
PB and O2 use strongly typed variables.

O2 variables are strong but supple! You can get close to interptetive scripts - mixing strings and numbers, and also relaxed rules on dimming.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 10:21:10 PM
O2 variables are strong but supple!

I didn't mean to detract from the dignity of strongly typed languages in general, and OxygenBasic, in particular. My point was that neither O2, nor PB, nor C go well together with the QB 4.5 variant-based original.

Can you give me a practical example of storing both integers and doubles in a common O2 array, and integers, doubles and strings in a variable called pvalue, without the need to maintain an auxilliary array that would concurrently store the values' data types, please?
Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 10:31:51 PM
Quote
Can you give me a practical example of storing both integers and doubles in a common O2 array, and integers, doubles and strings in a variable called pvalue, without the need to maintain an auxilliary array that would concurrently store the values' data types, please?

Very good point Mike and something I don't appreciate enough in SB. I need to ask Peter Verhas how much QB influence his design standards.

To answer your question about SB able to deal with C strings (null terminated strings) the answer is yes. Be aware as Charles and I discovered you can't directly assign a SB string pointer. Peter's MyAlloc is in play by default and using the SB API is the best way to pass strings within the SB C ext. module.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 21, 2014, 10:39:59 PM
In LeanLisp, I store all the variables and other entities as strings. Types are inferred during parsing, and value are transferred to the appropriate (strong) temp variables for processing.

I will try to conjure an example after my dawn siesta :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 10:50:35 PM
I will try to conjure an example after my dawn siesta :)

Please take your time, Charles, we aren't really in a hurry. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 10:57:29 PM
Be aware as Charles and I discovered you can't directly assign a SB string pointer.

1. Can you get a pointer to anything in SB without Charles' extension module? I'm aware of ADDRESSOF and associated FUNCALL -- what about pointers to SB variables in general?

2. Is Charles' extension module a prerequisite for SB to be able to communicate with any other precompiled extension module e.g. graphics?
Title: Re: Lisp in Basic
Post by: JRS on August 21, 2014, 11:30:11 PM
Be aware as Charles and I discovered you can't directly assign a SB string pointer.

1. Can you get a pointer to anything in SB without Charles' extension module? I'm aware of ADDRESSOF and associated FUNCALL -- what about pointers to SB variables in general?

If all you need is a simple FFI use the DYC ext. module (http://www.scriptbasic.org/forum/index.php/topic,105.msg230.html#msg230) from SB. Charles's DLLC was to add IUP, multi-threading and COM to the mix.

Quote
2. Is Charles' extension module a prerequisite for SB to be able to communicate with any other precompiled extension module e.g. graphics?

SB already has ready to use ext. modules. SDL GFX done in C BASIC is a rather recent addition. 

A few examples (http://www.scriptbasic.org/forum/index.php/topic,298.0.html)

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 11:37:20 PM
I haven't seen the FBSL version of the SBLisp project since the beginning. What is the current format? Does it look more like the original QB version or the SB version?

The FBSL version with GOSUB's de-interleaved is yet non-existent. An earlier version with <, >, /, - and ; fixed is available on the FBSL forum in this thread (http://www.fbsl.net/phpbb2/viewtopic.php?f=26&t=3028).
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 21, 2014, 11:51:37 PM
If all you need is a simple FFI use the DYC ext. module from SB.

Thank you. Does SB use the concept of pointers at all except in its ref variables and indirect function calls with FUNCALL? In other words, can you get a pointer to anything in SB with an operator and then do something useful with such a pointer further on in your code?
Title: Re: Lisp in Basic
Post by: JRS on August 22, 2014, 12:00:44 AM
Okay. I pushed your source and Windows executable to the FBSL folder on Bitbucket. You have R/W access there so if you can maintain your FBSL version that would be great.

BTW: We can't use the .fbs attribute for FBSL source files. Bitbucket thinks that attribute is an image file. I changed it to .fbsl to get it to work.
Title: Re: Lisp in Basic
Post by: JRS on August 22, 2014, 12:07:03 AM
Quote
Thank you. Does SB use the concept of pointers at all except in its ref variables and indirect function calls with FUNCALL? In other words, can you get a pointer to anything in SB with an operator and then do something useful with such a pointer further on in your code?

ADDRESS returns an internal SB serial number for the function which then can be used with other SB BASIC functions and passed as an argument for indirect calls from within the function. Argument count may vary and is available with besARGNR at the SB API level. The SB extension & embedding API is the only way to deal with the SB internals.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 22, 2014, 12:40:28 AM
ADDRESS returns an internal SB serial number for the function which then can be used with other SB BASIC functions and passed as an argument for indirect calls from within the function. Argument count may vary and tested at the SB API level. The SB extension & embedding API is the only way to deal with the SB internals.

Thank you.

Okay. I pushed your source and Windows executable to the FBSL folder on Bitbucket.

This isn't "okay" with me. The FBSL version will stay where it belongs on the FBSL site. I have never expressed my volition or intention to become the maintainer of a ScriptBASIC repository or project or fork and especially under the banner of GNU GPL and/or its compatibles. I have my beliefs and attitudes that I will hardly change, and I will stay with MIT and BSD in the foreseeable future. The FBSL branch shall remain open source as it is now and this product shall never be included in the official FBSL distribution. It shall be freely downloadable under the original Creative Commons' from the FBSL site for as long as the latter exists on the net.

This is about all that I have to say on this subject. Now please undo.
Title: Re: Lisp in Basic
Post by: Aurel on August 22, 2014, 12:55:40 AM
Mike
I would like to say that i prefer to believe in new languages like is PWCT than
in this hybrid basic-lisp.
Title: Re: Lisp in Basic
Post by: JRS on August 22, 2014, 01:03:34 AM
Quote
Now please undo.

Removed.

Good-night.
Title: Re: Lisp in Basic
Post by: RobbeK on August 22, 2014, 01:54:12 AM
Hi all,           recursion / iteration

First the definition of (nth i L)

(define nth
    (lambda (i L)
      ( if (= i 0) (car L)
           (nth (1- i) (cdr L)))))

which is perfectly symptomatic for this Lisp.
Historically imo Scheme was set up as a minimalistic Lisp , also proving that every situation can be solved with recursion - even today there are people promoting/advocating this (I'm not one of them).

the nth in natural language works like  (we're going to count 3rd slice .. of a bread
Mr Basic : 1 2 3
Mr Lisp : I take the first slice (car) and then I have the rest of my bread (cdr)
              I then take the first slice of the rest of my bread &
              then once again - now I have the 3rd slice ....

why this infantility , are they out of their mind doing this ???

infact not, because Lisp is variadic and typeless
Mr Basic can perfectly find the 4th house in a street very easily , the houses have the same size , he nows the start position and calculates the distance (offset) and he's there.

For Mr Lisp , things can be houses , streets , villages , cars ... there even may be an Aurel between them , he can not calculate the offset , he goes to the first and then there is a pointer to next -- to reach the fourth he has to travel through these 4 pointers. 
(reaching the last will take some time but a clever Mr Lisp  does   (car (reverse environment))    )

However, there is *no* need to follow such a mechanism when numbers are involved -- from there CL has arrays/vectors and they are easily assigned -- the elements are of a same type.

the solutions tried in Scheme are many, while (range i) still generates a list that is mapped (this happens in parallel , yet another problem ) , it also has (in-range i)  ..   but this sets up a stream (serial thus !!)  , because this happens in serial breaking conditions can be composed  , it even can do (in-naturals ) , containing all ! the natural numbers in a stream, the list assignments (naturals )  would take till the end of time to generate.
-Compiler technology   (the Austin-Kyoto compiler from the late Mr Schelter converts tail recursion in iteration ) -- and certainly the "Glorious Glasgow Haskell Compiler" does same and more.

This mechanism (even if an iterative operator is provided) is very frustating , it makes me write DLL's for CL , and make me ask question as to Mike about a verdict of sensibility of documentation.  In the Bigloo I use C-pointers to overcome these problems.

Only Mr Lütz Mueller from NewLisp boldly and bravely introduced
(address obj)  ---  the real memory address !!!!!!!!      GCL si::address gives a local Lisp address
(dup /char i)  --- allocates i bytes with the value of /char   p.e. /000 for the null character.

but in this Scheme, there is no single spark of any iterative construction I can use , expand ... if there were one, it would give me the feeling as when the sinking Das Boot hitting the bottom of the sea :
" Eine Schaufel Sand, der liebe Gott hat uns eine Schaufel Sand unter den Kiel geschmissen"

I found back my Lisp Book from Springer Verlag --  quoting it :  (about Recursion)
"Just because it is possible to push a pea up a mountain with your nose does not mean it is a sensible way"

The English name of the book is : "the art of Lisp programming"  -- maybe it is on-line somewhere.
(in the meantime I found next :
    http://www.moz.ac.at/sem/lehre/lib/bib/software/cm/Notes_from_the_Metalevel/index.html   ... seems very good !! )
(for the music lovers ---  who isn't ??)

best Rob

(addendum , just had a look at the forum linked by Aurel, one of his statements is that Lisp is not capable of even being a hobbyist programming language  -- therefor I add something written in Lisp in less than 20 ' )











.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 22, 2014, 03:02:23 AM
Mike,

This example indicates what is possible with o2 autoconversion, instead of using explicit conversion, or variants.

Code: [Select]
'AUTOCONVERSION


string s[100]
double d1,d2,d3

'no conversion needed

s[1]=4.25
s[2]=1.25
s[3]="10"

'transfer to doubles for direct arith expression
================================================

d1=s[1]
d2=s[2]
d3=s[3]

s[4]="Total: "+d1+d2+d3

print s[4] 'Total 15.5

'using autoconversion in function parameters
============================================

function sum(optional double n1,n2,n3,n4) as double
return n1+n2+n3+n4
end function

s[4]=sum s[1],s[2],s[3]
print s[4] '15.5


John,
Yes, I remember the tussle we had with passing char* params directly. It required the pointer to be created by SB - It wasn't a true char*. there were hidden attributes on the SB side.


Aurel,
Re: PWCT: th power is in the IDE, I think.


Rob,
Good Lisp reference.
Also:
Quote
"Just because it is possible to push a pea up a mountain with your nose does not mean it is a sensible way"
;D
Title: Re: Lisp in Basic
Post by: Aurel on August 22, 2014, 03:20:23 AM
Quote
Aurel,
Re: PWCT: th power is in the IDE, I think.

No Charles
This is something like new paradigma
Programming Witout Coding Technologie
Title: Re: Lisp in Basic
Post by: Aurel on August 22, 2014, 03:24:56 AM
Rob what is this ..
need Java  :o ....where is a lisp?
..and yes Lisp is not language for hobby programmers at all...
and i really ..really don't understand your obsession with Lisp ..
are you member on any Lisp-forum ..or something?

.
Title: Re: Lisp in Basic
Post by: RobbeK on August 22, 2014, 03:48:28 AM
Hi Aurel,

Yes, it needs Java to run -- it uses the Java Programmable Interface for the graphics.
Nono, not a member of a Lisp forum -- (my avatar is even my outfit when attending Lisp gatherings  ;)  as said before they are specialized in humiliating "the others"  )I fully understand the shortcomings of Lisp , but I also do understand its powers.
I also do understand same for languages as Pascal and Basic.
The symbiosis is happening ..  the now popular languages ..  Python , Ruby , Haskell contain a very lot of Lisp  -- what I'm hoping for is a language with both the strengths of something as basic together with something as lisp.

It certainly is not religion -- just my ideas are faster materialized with lisp ,  it may be a consequence of the job I did, I don't know -- I certainly will never do any categorizing concerning prog. lang. As said, I do understand the strength of imperative languages as basic     --   and I simply can not comment on many languages, simply because I do not know them.

best Rob 
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 22, 2014, 06:13:55 AM
Rob's hellish bouillon brewn at Lispian sabbatical gatherings: (a must-see in action! :D )

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 22, 2014, 06:59:53 AM
Aurel,

I would like to say that i prefer to believe in new languages like is PWCT than in this hybrid basic-lisp.

This project isn't intended as a basic-lisp hybrid. It is LISP written in BASIC. Same as thinBasic written in PB. Same as Oxygen written in FB. Same as Ruben (is it ruby?) written in O2.

PWCT is a Lego for script kiddies, a VB6 IDE promoted to the nth power of absurdity, and the essence of John's point & click nightmare. This paradigm has in fact been very well known to mankind for ages: if VB6 is a kindergarten, then PWCT is its nursery. :)

Rob is perfectly right in saying that there isn't really a question of a language vs. a language (you can't embrace the unembraceable in one hug anyway) but a language plus a language. The more pluses one has, the more powerful one is.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 22, 2014, 07:12:12 AM
Charles,

This example indicates what is possible with o2 autoconversion, instead of using explicit conversion, or variants.

Excellent! :D

While this isn't strictly "instead" but rather "halfway there", this should be more than sufficient for the needs of BASIC LISP in its Oxygen implementation.

Thanks a lot for the tip!


[EDIT] Will Oxygen's string functions, for example STR(), handle the elements of such an array as s[n] in you example correctly? Is garbage collection solid when re-assigning string/double/string/double/... values to the array elements?
Title: Re: Lisp in Basic
Post by: JRS on August 22, 2014, 08:06:07 AM
Hi Mike,

Is there something to update the SBLisp code with or is the current source it?

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 22, 2014, 08:40:35 AM
Hi John,

Not yet. Everything will be posted here immediately when ready.
Title: Re: Lisp in Basic
Post by: JRS on August 22, 2014, 08:49:57 AM
Thanks for the update Mike!

Can you post the top 5 SBLisp SUB/FUNCTION routines that would best be served by a C conversion?

Title: Re: Lisp in Basic
Post by: Charles Pegge on August 22, 2014, 09:30:32 AM
Quote
[EDIT] Will Oxygen's string functions, for example STR(), handle the elements of such an array as s[n] in you example correctly? Is garbage collection solid when re-assigning string/double/string/double/... values to the array elements?

I often check for missing garbage collection calls in such expressions. So far so good, but you may yet discover a leak in some novel combination :o
Title: Re: Lisp in Basic
Post by: Aurel on August 22, 2014, 09:38:58 AM
Quote
PWCT is a Lego for script kiddies, a VB6 IDE promoted to the nth power of absurdity

yes Mike maybe you have a right BUT how then explain that this project have
more & more users...
I don't understand what this people see in PWCT.
i am not impressed....
Title: Re: Lisp in Basic
Post by: JRS on August 22, 2014, 09:53:27 AM
@Aurel - Can you start a new PWCT thread and stop hijacking this one?
Title: Re: Lisp in Basic
Post by: RobbeK on August 22, 2014, 01:17:07 PM
Thanks Mike,

Bouillon ,,   maybe "борщ"  -- the colour in the middle sometimes matches ...  8)
Set up C-pointers now in CLisp , Clozure CL and Steel Bank CL  -- that Bigloo document helped a lot to understand things ...

best ,  Rob

ah, yes for the XBlisp Mandelbrot imho the most easy way is to set up a list with coordinates '( (-1.5 -1.5) .... (1.5 1.5) ) , then defining a function that takes a list (x y) - do the calculations when it bails out -- this function will be mapped on the list - resulting in a list of orbits -- with this (and (nth i L) ) it is easy to make a representation.  It surely will work , but it's all recursion.
It's all in my head -- should I code it -- resulting exec time may be very long...


Title: Re: Lisp in Basic
Post by: JRS on August 22, 2014, 02:08:04 PM
Hi Rob,

Quote
It's all in my head -- should I code it -- resulting exec time may be very long...

If it wouldn't take a lot of your time that would be great. All SBLisp Scheme code is helpful for testing the interpreter and for benchmarking between variations.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 22, 2014, 02:20:25 PM
Can you post the top 5 SBLisp SUB/FUNCTION routines that would best be served by a C conversion?

These should probably be GarbageCollect and its callees. But actually their code may still change. I understand your eagerness to do something useful but please don't rush me.

I split and convrted everything and got rid of bsd completely. Still there seems to be a typo left somewhere because files still don't want to load and get read properly. Interactive sessions seem to run OK.

Please have patience.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 22, 2014, 02:26:20 PM
Rob,

I second John's request and I'd like to make it even more imperative. We need code-intensive XBLisp programs for more thorough testing.

Speed doesn't make any difference at this point. Everything will a hundred times faster when translated to C and DynC and when OxygenBasic's JIT version becomes operative.

But we need the programs now. We don't have much time to design them ourselves because we are complete noobs. Mandelbrot will take you minutes to write but it will take us days to do the same.

MacRob, where are you with our ASCII Mandelbrot? :)
Title: Re: Lisp in Basic
Post by: JRS on August 22, 2014, 02:43:14 PM
Quote
please don't rush me.

Take all the time you need to do it right.

I was just going by the last info I had which was when I got up and was having coffee there would ba an update waiting. No fear, I was still able to carry on with the rest of my day.  ;)

Wow! Getting rid of BSD is something.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 22, 2014, 03:39:08 PM
Wow! Getting rid of BSD is something.

It made the file ~700 lines shorter and faster because incrementation/decrementation is unnecessary. All BSD did was count the current recursion depth. Now the subs exit early automatically in response to an error flag until surfaced in the main loop where the flag is cleared.

All functions are turned back to subs as there's no need to assign error returns. This should also make the code run a bit faster.

Interactive sessions run OK but file execution still fails.

Now I'm going to have a break and grab some sleep. Hopefully I'll isolate the bug tomorrow morning with a cleaner head.
Title: Re: Lisp in Basic
Post by: JRS on August 22, 2014, 04:00:13 PM
That sounds great. Looking forward to seeing it in action.

FYI - I gave up on the PBCC conversion after your warning of potential of a waste of time.

Title: Re: Lisp in Basic
Post by: JRS on August 22, 2014, 05:35:55 PM
I would like to make another proposal.

Lets not call it XBlisp any longer and lets call it BASIC Lisp. (BL for short) Each BASIC involved in the project can integrate with it in their own way and on their terms. I'm happy with SBLisp (Scheme BASIC Lisp) and since it's a language of its own, the SB factor is under the covers just like C is under the covers for SB. When you run the SBLisp program, unless you knew it was written in SB, there is no reference to it. My goal is to get SBLisp as an extension module and interacting with SB. I'm not a Lisp programmer and learning from the other members of the project.

FYI - For those noticing site slowdowns, I hope we have it resolved. (China connections trying to use my server as a proxy to get around their oppressive government.)

O2 Forum Activity - 1 Year

(http://files.allbasic.info/O2/o21yract.png)
Title: Re: Lisp in Basic
Post by: JRS on August 22, 2014, 10:35:37 PM
Rob,

Are you able at this time to give us a usability evaluation of BASIC Lisp? I guess what I'm asking for is Arthur's Scheme Lisp a sub-set, a unique hybrid or something else? I want to try Scheme code I find but don't know if it's compatible with BL. I feel we are on to something with this if we can combine the best of Lisp and Basic in a seamless manor. I don't think Mike would be spending the time on this and using a rivals BASIC if he didn't see something of value. (for FBSL or any traditional BASIC compatible that follows QB rules)

 
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 02:46:21 AM
Hi John,

Quote
Lets not call it XBlisp any longer and lets call it BASIC Lisp.
Whatever as long as it isn't called SBLisp here. Sounds too confusing to me.

Quote
O2 Forum Activity - 1 Year
Haven't I brought along a couple of K's since registered? ;)

Quote
I don't think Mike would be spending the time on this and using a rivals BASIC...
We are neither rivals nor competitors. For me, SB is just another BASIC like O2 or thinBasic among those that can interest me to the extent of actually coding something in them.

I'm a veteran and I am just doing what I please. You may call it "fooling around". But once I lay my hands onto something, I feel obliged to bring it to the end. I looked through your SB code and saw it was inoperative, and then I re-translated the original into FBSL and it worked. I then saw a challenge in making the SB code work too and that's how I got hooked onto it. Then Oxygen was naturally added as long as we were on Charles' forum, and this is how I came to be where I am.

I don't have any special plans for LISP for FBSL; just thought it might be an entertaining optional addition to the three languages available in FBSL. I'm not a miser and I will be glad if it works out in the end and similar modules will appear in SB and O2 too.

Apart from that, there's no conspiracy or strategic aspirations in my BL activity. :)


P.S. I have fixed about three dozens bugs in my yesterday's code and now files are loaded correctly too. There is just one offending sub left -- SUB EvalSequence() -- that's called three times in other subs and that still breaks the natural program flow. The problem is it isn't really a sub but rather a simple loop that recurses deeper and deeper but it doesn't have a natural exit of its own. I have yet to invent a way to get it out of recursion all by itself before BL starts to function faultlessly. But again, I need some rest after almost 6 hours of tapping on my keyboard.
Title: Re: Lisp in Basic
Post by: RobbeK on August 23, 2014, 03:00:20 AM
all,    ...

Made a prototype for BL in NewLisp -- as this language is a kind of mix between Scheme and CL , the syntax is chosen very close to BL.  However, I do have to convert all the iterations now.
As this is about a 2D object - it will not be story of the "the nose , the pea & the mountain" , but  "the nose , two peas & a mountain "
OK - everything can be done by recursion , but it's a p in the a  (with a capital P here)

the code in iterative Lisp / Scheme is simple :

----------------------------------------------------------

(define grid '())
(define nr 40)
(define mapped-grid '())
(define car (lambda (L) (L 0)))
(define cadr (lambda (L) (L 1)))

(define sq (lambda (x) (mul x x)))

(define level
   (lambda (L)
     (letn ( (x (car L)) (y (cadr L)) (rc x) (ic y) (it 11) (orb 0) (dp 0) (ret 0) )
       (dotimes (i it (> orb 4))
          (setq dp x)
          (setq ret i)
          (setq x (add rc (sub (sq x) (sq y))))
          (setq y (add ic (mul 2 dp y)))
          (setq orb (add (sq x) (sq y)))) ret )))

(define fill-grid
     (lambda (m)
       (setq grid '())
       (let ((xo -1.5) (yo -2.3) (dz (div 3 m)) (x 0) (y 0) (n (+ 1 m)) )
         (dotimes (i n)
           (setq x (add xo (mul i dz)))
           (dotimes (j n)
              (setq y (add yo (mul j dz)))
                (push (list y x) grid))))))


(define map-grid
    (lambda () (setq mapped-grid (map level (reverse grid)))))

(define print-grid
    (lambda ()
      (letn ((length-grid (length mapped-grid))  (nl (sqrt length-grid)))
        (dotimes (i length-grid)
         (let ((item (mapped-grid i)))
          (when (= 0 (mod i nl)) (println))
          (if (= 10 item)
                 (print item )
                 (print item " ")))))))

(define main
    (lambda ()
       (println "Levels of Mandelbrot - NewLisp")
       (println "------------------------------")
       (println)
       (let ((answer ""))
         (while (!= answer "q")
            (print "Give Width/height - [ q quits ] : ")
            (setq nr (read-line))
            (println)
            (fill-grid (int nr))
            (map-grid)
            (print-grid)
            (println)
            (println)
            (println)  ))))

(main)

--------------------------------------------------  an executable is attached   (try 32 or so)

best Rob
(John,  I'll answer after the coding experience this evening )
(Mike, is it possible at the level you're working on this code to add  only something as loop and exit-loop (from here everything can build to make a "practical" Scheme   )



.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 05:02:15 AM
Hi Rob, :)

This really looks nice but it doesn't seem to follow the BASIC and C originals that I posted earlier.

To make our conversation more precise and technical, can you please give me very brief and definitive answers to the following list of my questions? I'd like to see all the questions answered even if in the simplest form of "yes" or "no".

1. Are you able to write general LISP code (not for BL but for yourself) exclusively in Scheme? No NewLisp, no CL, no Bigloo, no anything but pure refined Scheme from the beginning of the program to its very end, even if you don't like Scheme personally?

2. If yes then exactly which Scheme package would you use for that? Can you give me a link to its documentation so that I could get acquainted with its base vocabulary (without libraries, includes, extensions, user-defined macros, etc.)?

3. Are there any iterators like for, do, loop, while, etc. in the vocabulary of Scheme package that you would use for your code as per Items 1 and 2 above?

4. You have designed iterate and iterate+ from the keywords available in BL's existing vocabulary. If the answer to Item 3 above is "yes", then can you design do and while too just like you designed your iterate and iterate+? (your arguments that it would be too slow or something will be ignored because speed doesn't really matter to us at this point)


I'm looking forward to your soonest reply.
Title: Re: Lisp in Basic
Post by: JRS on August 23, 2014, 08:24:41 AM
Heads-Up - The Bitbucket repository name (and link) have been change to reflect the new name for the project.

https://bitbucket.org/ScriptBasic/basic_lisp

Please update your shortcuts and bookmarks.

Title: Re: Lisp in Basic
Post by: JRS on August 23, 2014, 09:31:55 AM
Quote from: Mike
Haven't I brought along a couple of K's since registered?

Just the Aurel catalyst effect has earned your salt.

I would also like to purpose that we start using the AllBASIC IRC more when we are working through a problem rather than flood the O2 forum. The forum should be used to post progress and query for ideas. I think the IRC is better for discussing problems and solutions.
Title: Re: Lisp in Basic
Post by: RobbeK on August 23, 2014, 11:04:34 AM
Hi Mike,

1) Yes -- but what is pure refined Scheme , next are the language specifications the : r5rs standard , you can find the iterator (do ....) belonging to the library syntax -- if some one should refuse these , you will also have to remove let let* "and" "or" cond .... etc etc http://www.schemers.org/Documents/Standards/R5RS/r5rs.pdf

2) Everything is here , but there is nothing that can build any iteration.  I mean things like the modulus is missing and also the squareroot  , but these are easy to define  (pe (define sqrt (lambda (x) (exp (/ (log x) 2))))  -- but no iteration can be defined without any primitive available -- only (do ..  ) is missing (it will build all other iterative constructions)

3) (do .. ) the most general , I only need one ..  remark that this Scheme has no "named let" either

4) iterate/iterate+ are recursive constructions poorly simulating iteration , and only on one level , they can not be nested because based on single recursion - I can write double-recursive mechanisms and call these iterate2 or something like.

I started converting the NewLisp code now -- and this is an example of building an xy space recursively

(define fill-grid
   (lambda (nrx xo dx nry yo dy matrix dup)
       (if (and (= 0 nrx) (= 0 nry)) matrix
         (if (= 0 nry) (fill-grid (1- nrx) xo dx dup yo dy matrix dup)
           (fill-grid nrx xo dx (1- nry) yo dy
            (cons (list (+ xo (* nrx dx)) (+ yo (* nry dy))) matrix) dup)))))

a recursive way to fill a list with 2D coordinates  (it works correctly) - it sets up a list of lists containing (x y)

I think there's something fundamental wrong with languages missing any iterative construction -- p.e. if the main function runs an infinite loop , there's no other way of calling itself to run ... a mechanism as (do .. ) will provide everything needed to overcome such bizar situations.

best , Rob
 
Title: Re: Lisp in Basic
Post by: JRS on August 23, 2014, 11:28:14 AM
Rob,

Quote
I mean things like the modulus is missing and also the squareroot ...

Please don't waste your time with defining math functions. These are VERY easy to add to BL. (BASIC functions providing the juice)

Title: Re: Lisp in Basic
Post by: RobbeK on August 23, 2014, 12:12:54 PM
Hi John,

Don't worry ,  just needed it because from a square grid z² , i need to put a newline after every z  (and that's sqrt(z²) ) (or specific the sqrt from the length that represents the list of xy coordinates  ::) -- i only define the things needed for the code.

-- just "lazy" definitions , I add them when needed ...

best Rob
(if it were possible the iterative (do ... ) could be included  ...  recursion is such a waste of memory , speed , etc ... )
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 12:18:59 PM
Quote
I mean things like the modulus is missing and also the squareroot ...
Please don't waste your time with defining math functions. These are VERY easy to add to BL. (BASIC functions providing the juice)

Rob,

Currently we have arith operators and also (sin), (cos), (atan), (exp), and (log).

I can also add the following procedures right away: (tan), (cotan), (sqrt), (mod), and (pow). If you want me to do it, please give me the exact names of these functions in LISP and the exact typical syntax how they should be written in a LISP program together with their operands.

Until then, please keep on using BL lambdas to emulate them if possible.
Title: Re: Lisp in Basic
Post by: JRS on August 23, 2014, 12:26:51 PM
Tom added RAD and filled in the stubs in SB with the following functions. (SB 2.2 only)

Code: [Select]
' Given the starting value of 34 degrees, calculate radians.
' Given the radian value, calculate TAN, COTAN, SECANT and COSECANT.
' Given the TAN, COTAN, SECANT and COSECANT values,
' calculate the ATAN, ACTAN, ASECANT and ACOSECANT.
'
degval = 34
radval = RAD(degval)
zerval = 0

tanval = TAN(radval)
cotval = COTAN(radval)
secval = SECANT(radval)
cseval = COSECANT(radval)

ataval = ATAN(tanval)
actval = ACTAN(cotval)
aseval = ASECANT(secval)
acoval = ACOSECANT(cseval)

hsinv = HSIN(radval)
hcosv = HCOS(radval)
htanv = HTAN(radval)
hsecv = HSECANT(radval)
hcosc = HCOSECANT(radval)
hcotv = HCTAN(radval)

print "\nThe following 8 functions accept radians as their argument, so we "
print "use the\nnew RAD() function to convert ",degval," degrees to ",radval," (",str$(radval),") radians.\n\n"

print "Tangent\t\tCotangent\tSecant\t\tCosecant\n"
print "TAN()  \t\tCOTAN()  \tSECANT()    \tCOSECANT()\n"
print tanval," \t",cotval,"\t",secval," \t",cseval,"\n"
print str$(tanval)," \t",str$(cotval)," \t",str$(secval)," \t",str$(cseval),"\n\n"

print "Arctangent\tArccotangent\tArcsecant\tArccosecant\n"
print "ATAN()    \tACTAN()  \tASECANT()\tACOSECANT()\n"
print ataval," \t",actval," \t",aseval," \t",acoval,"\n"
print str$(ataval)," \t",str$(actval)," \t",str$(aseval)," \t",str$(acoval),"\n\n"

print "There are 6 Hyperbolic functions. They also accept radian arguments.\n\n"
print "H-Sine\t\tH-Cosine\tH-Tangent\n"
print "HSIN()\t\tHCOS()  \tHTAN()\n"
print hsinv," \t",hcosv," \t",htanv,"\n"
print str$(hsinv)," \t",str$(hcosv)," \t",str$(htanv),"\n\n"

print "H-Secant\tH-Cosecant\tH-Cotangent\n"
print "HSECANT()\tHCOSECANT()\tHCTAN()\n"
print hsecv," \t",hcosc," \t",hcotv,"\n"
print str$(hsecv)," \t",str$(hcosc)," \t",str$(hcotv),"\n\n"

Output

Code: [Select]
jrs@laptop:~/sb/sb22/test$ scriba testmath.sb

The following 8 functions accept radians as their argument, so we use the
new RAD() function to convert 34 degrees to 5.934119e-01 (0.593412) radians.

Tangent Cotangent Secant Cosecant
TAN()  COTAN()  SECANT()    COSECANT()
6.745085e-01 1.482561e+00 1.206218e+00 1.788292e+00
0.674509 1.482561 1.206218 1.788292

Arctangent Arccotangent Arcsecant Arccosecant
ATAN()    ACTAN()  ASECANT() ACOSECANT()
5.934119e-01 5.934119e-01 5.934119e-01 5.934119e-01
0.593412 0.593412 0.593412 0.593412

There are 6 Hyperbolic functions. They also accept radian arguments.

H-Sine H-Cosine H-Tangent
HSIN() HCOS()  HTAN()
6.288574e-01 1.181297e+00 5.323451e-01
0.628857 1.181297 0.532345

H-Secant H-Cosecant H-Cotangent
HSECANT() HCOSECANT() HCTAN()
8.465274e-01 1.590186e+00 1.878481e+00
0.846527 1.590186 1.878481

jrs@laptop:~/sb/sb22/test$

P.S. I have a cleaned up version of this somewhere using SB FORMAT().
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 12:39:11 PM
Mehdi added the following math and trig functions to FBSL:

Code: [Select]
// Conversion d'angles degrés <-> radians
{"degrees", r2d},
{"r2d", r2d},
{"radians", d2r},
{"d2r", d2r},

// Fonctions trigonométriques (versions radians = normal)
{"cos", cos},
{"cosec", cosec},
{"cotan", cotan},
{"sec", sec},
{"sin", sin},
{"tan", tan},

{"acos", acos},
{"acosec", acosec},
{"acotan", acotan},
{"asec", asec},
{"asin", asin},
{"atan", atan},

{"cosh", cosh},
{"cosech", cosech},
{"cotanh", cotanh},
{"sech", sech},
{"sinh", sinh},
{"tanh", tanh},

{"acosh", __acosh},
{"acosech", acosech},
{"acotanh", acotanh},
{"asech", asech},
{"asinh", __asinh},
{"atanh", __atanh},

// Autres notations (~VB) :
{"atn", atan},
{"cosin", cos},
{"sinus", sin},
{"tgn", tan},

{"arccos", acos},
{"arccosec", acosec},
{"arccotan", acotan},
{"arcsec", asec},
{"arcsin", asin},
{"arctan", atan},

{"hcos", cosh},
{"hcosec", cosech},
{"hcotan", cotanh},
{"hsec", sech},
{"hsin", sinh},
{"htan", tanh},

{"harccos", __acosh},
{"harccosec", acosech},
{"harccotan", acotanh},
{"harcsec", asech},
{"harcsin", __asinh},
{"harctan", __atanh},

// Version degrés (pas toutes) :
{"cosd", cosd},
{"cosecd", cosecd},
{"cotand", cotand},
{"secd", secd},
{"sind", sind},
{"tand", tand},

{"acosd", acosd},
{"asind", asind},
{"atand", atand},

// Autres notations (degrés) :
{"arccosd", acosd},
{"arcsind", asind},
{"arctand", atand},

// Notations V2 :
{"ctnd", cotand},
{"secd", secd},
{"cscd", cosecd},

// Fonctions de racines et puissances
{"sqrt", sqrt},
{"sqr", sqrt},
{"cbrt", __cbrt},
{"cbr", __cbrt},
{"square", square},
// voir aussi xrt, nrt, pow dans dbl_two


// Fonctions exponentielles et logarithmes
{"exp2", __exp2},
{"expm1", __expm1},
{"exp", exp},

{"ln", log},
{"log", log},
{"log10", log10},
{"log1p", __log1p},
{"log2", __log2},
{"logb", logb},
// voir aussi logx, logn dans dbl_two

// Fonctions d'arrondi
{"round", round},
{"ceil", ceil},
{"floor", floor},
{"nearbyint", nearbyint},

// Valeur absolue
{"abs", fabs},
{"fabs", fabs},

// Fonctions d'erreur
{"erf", erf},
{"erfc", erfc},

// Fonctions diverses
{"lgamma", lgamma}

// Autres
{"rnd", rnd}
{"rand", rand}
{"randint", randint}

{"atan2", atan2},
{"atn2", atan2},
{"arctan2", atan2},

{"logx", logx},
{"logn", logx},

{"xrt", xrt},
{"nrt", xrt},

{"pow", pow}
{"gcd", gcd}, // PGCD
{"scm", scm}, // PPCM

not counting approx. 30 math constants.

Mike enriched them with the following:

Code: [Select]
__f1("sgn", Sgn, 1),
__f1("min", MiN, 2),
__f1("max", MaX, 2),
__f1("min3", MiN3, 3),
__f1("max3", MaX3, 3)

and also added a layer of 150 single-precision vector and square matrix functions.


Now what?
Title: Re: Lisp in Basic
Post by: JRS on August 23, 2014, 12:58:50 PM
Quote
Now what?

I would say Rob has a wealth of MATH functions at his disposal in BL. (SB min set / FBSL full extended math library)

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 01:04:49 PM
IMO the additions I suggested coupled with what's already in BL would make a perfect basis for most common everyday calculations. Everything extra should come from a math library/extension at a later stage.

We aren't planning intensive math calc in BL right now, are we?
Title: Re: Lisp in Basic
Post by: JRS on August 23, 2014, 01:11:17 PM
Quote
We aren't planning intensive math calc in BL at this stage, are we?

Good point.

Just to make sure we are all on the same page, the ongoing goals as I understand them are as follows.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 01:13:00 PM
Generally, yes.

I'm writing a short report with my findings on the usability of Lisp-in-Basic code for the needs of SB, O2, and FBSL. I have tried many things, and I have failed many times. I want to discuss with you my vision of what we can do based on my trial and error.
Title: Re: Lisp in Basic
Post by: RobbeK on August 23, 2014, 01:14:48 PM
Hi John , Mike

Finished something (doesn't crash - draws - needs fine-tuning ) post it tomorrow after testing ...

One more time  ;)  the importance of iteration -- in Lisp , things are assigned parallel   like (let .... ) etc ...  this makes things possible as
(define a '(a b))
(set! a (list (car (cdr a)) (car a)))
-> (b a)
a swap without declaring a temp. variable

this is a good example from the code :

--------------------------------------

(define sq (lambda(x) (* x x)))
 
(define level
   (lambda (it x y rc ic orb)
      (if (or (= it 0) (> orb 4)) it
          (level (- it 1) (+ rc (- (sq x) (sq y)))
                 (+ ic (* 2 x y)) rc ic (+ (sq x) (sq y))))))
-----------------------

the nucleus of the program !  it calculates the orbit and gives back how many iterations were needed to reach the condition more than 4 or a max of iterations -- but this is no iteration, this is recursion - which means the parameters are bound parallel, which means that the calculation of the orbit (+ (sq x) (sq y)) uses the old values of  x and y and not the new calculated ones, for this reason I should have to calculate them once again - or set up local variables every recursion cycle.
Remark the difference with NewLisp , any CL , and probably any other Scheme :

(define level
   (lambda (L)
     (letn ( (x (car L)) (y (cadr L)) (rc x) (ic y) (it 11) (orb 0) (dp 0) (ret 0) )
       (dotimes (i it (> orb 4))
          (setq dp x)
          (setq ret i)
          (setq x (add rc (sub (sq x) (sq y))))
          (setq y (add ic (mul 2 dp y)))
          (setq orb (add (sq x) (sq y)))) ret )))
-----
assigned in sequence --

Is it possible to add any (no mather what ever) iterative , looping mechanism ???

best Rob



 

Title: Re: Lisp in Basic
Post by: JRS on August 23, 2014, 01:17:59 PM
Quote
I'm writing a short report with my findings on the usability of Lisp-in-Basic code for the needs of SB, O2, and FBSL. I have tried many things, and I have failed many times. I want to discuss with you my vision of what we can do based on my trial and error.

Can we do this on the AllBASIC IRC instead? I promise it will result in a more productive use of our time and with a better understanding of the issues. I can attach a copy of the IRC session log for others not directly involved.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 01:39:03 PM
I'm curious why Rob is almost never responding to the subject of others' messages?

I am not going to add any loops until he shows me definitely and unequivocally a Scheme in which such loops are present by definition. I am not going to add any more math and trig functions until he gives me the exact formulation of their syntax. I do not want to breed lexicographical bastards in the initially pure Schem-atic environment of BL without the exact reason why I should do just this. I am not a LISP programmer and I need motivated guidance which Rob so far denies to offer.

BL is currently written as Scheme-in-Basic, not as Common-Lisp-in-Basic. Are we going to re-write it as Common Lisp or should we keep it as Scheme?

I would be greatful to hear John's and Rob's responses to this question. I would also appreciate Charles' opinion on that if possible.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 01:43:42 PM
Can we do this on the AllBASIC IRC instead?

Only if Rob is there and takes active part in the conversation. If not, we can simply continue here as we always did. Don't see any reason why this thread can't be as effective as an IRC. We're talking business, after all.
Title: Re: Lisp in Basic
Post by: JRS on August 23, 2014, 01:53:07 PM
The best way to use the IRC is get a good IRC client, connect to the AllBASIC channel and forget about it. The IRC client will notifiy you of activity. You will be amazed how much can be accomplished in a focused chat session. This is the last I'm going to say about this. I'm always there and happy to discuss BASIC topics of value.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 01:56:47 PM
Rob,

Quote
Remark the difference with NewLisp , any CL , and probably any other Scheme

SCHEME is the key word in this sentence! I am not asking about NewLisp or CL. I need to see at least one SCHEME that does just that with my own eyes, not "probably" and not "any other", but one particular Scheme and now.

Can you do that for me, please?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 02:11:13 PM
John, we are flooding the thread with irrelevant things piled on top of our immediate issues. It is becoming difficult to attract the attention of the addressee when meaningful messages are diluted with irrelevant propaganda and counter-propaganda.

Let's keep our country clean. I need answers from Rob and I don't want to listen to anything else.

I have spent a week of my life on this project and I think I'm entitled to hear answers to the questions I've been posting here a dozen times again. I will not stir a finger until I have them answered:

1. Show me the Scheme that has looping in it. I want to see its commands and their syntax.

2. I will add the looping only based on what I will see in at least one such Scheme available on the net.

3. Give me the Scheme names and syntax for (tan), (cotan), (sqrt), (pow) and (mod) and I will immediately add them to BL.


Is it so difficult just to spend 30 seconds and give me what I need? I am not asking out of sheer curiosity; I am currently the developer of this project and everything new in it comes from under my fingers. I must know what I should do before I waste yet another week for nothing.

Thanks much everyone for their attention.



[UPD] All questions answered. John and Rob, thank you for your valuable feedback!
Title: Re: Lisp in Basic
Post by: JRS on August 23, 2014, 02:18:41 PM
Sounds like a good plan to me. Let me know if there is anything I can do.

http://en.wikibooks.org/wiki/Scheme_Programming/Further_Maths

This Scheme code from WikiBooks doesn't seem to complain.

Code: [Select]
;;; finding if an element exists in that list                           
                                                                         
; (define exists-in?                                                     
;   (lambda (ele lis)                                                   
;     (cond ((null? lis) #f)                                             
;           ((equal? ele (car lis)) #t)                                 
;           (else (exists-in? ele (cdr lis)))                           
;     )                                                                 
;   )                                                                   
; )                                                                     
                                                                         
;;; 'mapping' each element of the list to some value                     
                                                                         
(define plustwo                                                         
  (lambda (lis)                                                         
    (cond ((null? lis) nil)                                             
          (else (cons (+ (car lis) 2)                                   
                      (plustwo (cdr lis)))                               
          )                                                             
    )                                                                   
  )                                                                     
)                                                                       
                                                                         
;;; 'fold up' a list of such values into a single value                 
                                                                         
(define foldr                                                           
  (lambda (f e lis)                                                     
    (cond ((null? lis) e)                                               
          (else (f (car lis) (foldr f e (cdr lis))))                     
    )                                                                   
  )                                                                     
)                                                                       
                                                                         
;;; use this folding function to define a function called any           
                                                                         
(define any                                                             
  (lambda (pred lis)                                                     
    (foldr (lambda (x acc) (or x acc))                                   
           #f                                                           
           (map pred lis)                                               
    )                                                                   
  )                                                                     
)                                                                       
                                                                         
;;; Using this function we can re-write exists-in?                       
                                                                         
(define exists-in?                                                       
  (lambda (ele lis)                                                     
    (any (lambda (x) (equal? x ele)) lis)                               
  )                                                                     
)                                                                       

jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb looptest.scm
SBLisp - Scheme BASIC Lisp

(define plustwo
  (lambda (lis)
    (cond ((null? lis) nil)
          (else (cons (+ (car lis) 2)
                      (plustwo (cdr lis)))
          )
    )
  )
)
PLUSTWO
(define foldr
  (lambda (f e lis)
    (cond ((null? lis) e)
          (else (f (car lis) (foldr f e (cdr lis))))
    )
  )
)
FOLDR
(define any
  (lambda (pred lis)
    (foldr (lambda (x acc) (or x acc))
           #f
           (map pred lis)
    )
  )
)
ANY
(define exists-in?
  (lambda (ele lis)
    (any (lambda (x) (equal? x ele)) lis)
  )
)
EXISTS-IN?
T
0](quit)
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 02:47:50 PM
Thanks a lot, John,

This is indeed very informative and helpful. I'm removing question 3 from the agenda.


I think
Code: [Select]
...........
    (foldr (lambda (x acc) (or x acc))
           #f           ; <== probably wrong and should BE (), which is BL's symbol for FALSE
           (map pred lis)
    )
.............
wouldn't be correct and would throw an exception at run time. In fact, you haven't changed the grammar for FALSE, you only made BL print F instead of () to the console. But BL wouldn't recognise F as a valid input for FALSE.
Title: Re: Lisp in Basic
Post by: JRS on August 23, 2014, 03:04:35 PM
 :-\  I had a bad feeling about changing that. Please put it back the way it was.
Title: Re: Lisp in Basic
Post by: RobbeK on August 23, 2014, 03:17:33 PM
Mike,

"1. Show me the Scheme that has looping in it. I want to see its commands and their syntax."

I gave you a link to the official r5rs Standard - (attached) ,
I also asked you what "a pure Scheme" means : is it the one of Sussman and Steel (?) , the original or what ? you did not answer and If you have those documents, please give the links and I will read these.

 2.  I will add the looping only based on what I will see in at least one such Scheme available on the net.
ANY scheme I know has "named let" :

------------------------------------

  "Named `let'" is a variant on the syntax of let which provides a more general looping construct than `do' and may also be used to express recursions. It has the same syntax and semantics as ordinary `let' except that <variable> is bound within <body> to a procedure whose formal arguments are the bound variables and whose body is <body>. Thus the execution of <body> may be repeated by invoking the procedure named by <variable>.

(let loop ((numbers '(3 -2 1 6 -5))
           (nonneg '())
           (neg '()))
  (cond ((null? numbers) (list nonneg neg))
        ((>= (car numbers) 0)
         (loop (cdr numbers)
               (cons (car numbers) nonneg)
               neg))
        ((< (car numbers) 0)
         (loop (cdr numbers)
               nonneg
               (cons (car numbers) neg)))))   
          ==>  ((6 1 3) (-5 -2))

--------------------------------------------  from MIT   (p.s. the "named let" easily permits to define (while ) (until ) etc ...

3. Give me the Scheme names and syntax for (tan), (cotan), (sqrt), (pow) and (mod) and I will immediately add them to BL.

I do not need those (it was John who told not to spend much time on these - I did not spend any time on them, and just wrote what I needed) - everything is there that these can be constructed from what's available (I gave an example of (sqrt . ))- what is NOT available is any mechanism that will allow iteration that's the crucial point imho --

The examples I gave are compares -- because nothing compares to itself -- it's not about CL has that , or ExOsChEmE has this , it's about the importance of things - Recursion is perfect for mathematics , the formulae are even more compact , but not for program flow -- 

btw : your answer from 10th this month
---------------

@Rob:

Thanks for reminding me about (do). In fact I'm keeping it in mind. I'm simply waiting for when John finds a little time to get acquainted with the Scheme vocabulary to tell me that there's no (print) in there but rather (display), and that there's not only (for-each) in there but also (do)

---------------------------------






.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 03:24:04 PM
:-\  I had a bad feeling about changing that. Please put it back the way it was.

On the contrary, John,

If #t and #f is a natural and canonical way for Scheme to denote its TRUE and FALSE (nil) then we'd better change BL's symbols to match.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 23, 2014, 04:18:40 PM
Thanks for the feedback, Rob.

"1. Show me the Scheme that has looping in it. I want to see its commands and their syntax."
I gave you a link to the official r5rs Standard - (attached) ,
I also asked you what "a pure Scheme" means : is it the one of Sussman and Steel (?) , the original or what ? you did not answer and If you have those documents, please give the links and I will read these.
 2.  I will add the looping only based on what I will see in at least one such Scheme available on the net.
ANY scheme I know has "named let" :

------------------------------------

  "Named `let'" is a variant on the syntax of let which provides a more general looping construct than `do'....

Quote from: Mike
@Rob:
Thanks for reminding me about (do). In fact I'm keeping it in mind. I'm simply waiting for when John finds a little time to get acquainted with the Scheme vocabulary to tell me that there's no (print) in there but rather (display), and that there's not only (for-each) in there but also (do)

This isn't entirely correct.

Please take a look at the attached picture which is a snippet of your own and note the red squares. In my opinion, a "library" is an extension housed in a module external to the language's engine. It's like GetTickCount() becoming available to you only when you load kernel32.dll. Until then, you can rely only on BASIC's internal TIMER.

The red squares are arousing a very strong suspicion in me that all this looping rather comes from a library extension of Scheme language but is not its intrinsic feature.  I think I already expressed it in this thread but I don't remember anybody confirm or refute my suspicion.

So you ask me to include non-standard library features in the main engine of the language ignoring at the same time my inquiries about its standard features  ( tan, cotan, mod, etc) that are still missing from there. You're discarding them as irrelevant for your current work but I can hardly discard them either because it's a complete language that I'm trying to finalize.

Can you confirm again that your example documentation on looping pertains to Scheme's vocabulary proper and not to the Scheme language extensions? I need to know it definitevely to take a decision how to host them in BL code; i.e. whether they should go in the main keyword hash table automatically on load or rather be loaded only in response to a command line switch or parameter like any extension would normally load in other languages.

Thanks for your help.

.
Title: Re: Lisp in Basic
Post by: RobbeK on August 24, 2014, 12:40:21 AM
Hi Mike,

Yes, it is library syntax , and so is (let ) (let* ) (and ) (or ) (cond ) (case ) which are present in this Scheme etc etc ,

Furthermore from this document :

It is required that every implementation of Scheme support
all features that are not marked as being optional
. Implementations are free to omit optional features of Scheme
or to add extensions, provided the extensions are not in
con ict with the language reported here. In particular,
implementations must support portable code by providing
a syntactic mode that preempts no lexical conventions.

Documentation from INRIA  (http://en.wikipedia.org/wiki/French_Institute_for_Research_in_Computer_Science_and_Automation )

There are people that find it difficult to accept Peano’s rule of inference.
Therefore, let us linger a little on it. Equation 5.1 is true for n=0, since this
is the trivial case of our demonstration. It is also true for n=1, since it is
true for n=0, and we have demonstrated that it is true for (n+1) whenever
it is true for n. It is also true for n=2, since it is true for n=1, and we
demonstrated that it is true for (n+1), if it is true for n. Got the idea?
In the Algorithm Language Scheme there are three ways to perform in-
terations, and inductions, to wit:

do-loop Below you will find how to define factorial using a do-loop.
1:=> (define (fact n)
(do ( (i 1 (+ i 1)) (acc 1 (* i acc)) )
( (> i n) acc) ) )
fact
1:=> (fact 5)
120


Named let
1:=> (define (factorial n)
(let iter ( (i 1) (acc 1) )
(if (> i n) acc
(iter (+ i 1) (* i acc)) )) )
factorial
1:=> (factorial 5)
120


Tail recursive function
1:=> (define (tail-fact i n acc)
(cond ( (> i n) acc)
(else (tail-fact (+ i 1) n (* i acc)) )) )
tail-fact
1:=> (define (fact n) (tail-fact 1 n 1))
fact
1:=> (fact 5)
120

It may be the pure no-library "syntax" refers to the original Sussman / Steel / etc experiment which I think contained no loop mechanism and in those days was named Schemer - but personally I never would use such , unless in a masochistic mood.

best Rob

Hi John,

Do you have contact with Mr Sussman ?  (i think to remember mentioning him).
You can ask him -- he is one of the important members of the Scheme standard committee.

best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 24, 2014, 12:44:13 AM
Based on the Lamer's Guide to Scheme (http://en.wikibooks.org/wiki/Scheme_Programming) (which is exactly my current level) that John has provided earlier in this thread, there are no ways to express iteration in Scheme per se other than through recursion:

Quote from: Scheme Programming #1
Scheme has no while-loops or for-loops. In Scheme a similar effect is achieved by simply letting a function call itself.
Quote from: Scheme Programming #2
Scheme is very odd in one sense, it has no expressions designed for looping, repeating or otherwise doing something more than once at a general level.

Iterative recursion and looping over lists are performed in canonical Scheme with the instruments that are already available in BASIC Lisp: named and anonymous lambdas, if and cond clauses, and for-each and map procedures. Anything extra to these is regarded as syntactic sugar and is provided in a language extension library for ease of use for less recursively-minded (call it less introspective hehe) programmers.

There is however one important circumstance that the BASIC Lisp interpreter will never be able to provide:
Quote from: Scheme Programming
... whenever a function calls itself in such a way that the same effect can be implemented by a loop or iteration, Scheme guarantees that the compiler will rewrite it to a loop at the machine-code level, so you will never run out of stack space or need useless time to call procedures when what you try to do can be rewritten to a loop ...

(Rob and Charles, I wonder what the algorithm may look like to programmaticaly analyze a Scheme recursive procedure and unroll/fix/recode it automatically into a loop?)

So now I'm adding Scheme's base functionality that's still missing in BASIC Lisp which is:

-- radian-based trigonometry: tan and cotan, and also arc and hyperbolic trig in the languages where it is available (FBSL has it all intrinsically, not sure about SB);
-- power functions: sqrt and expt (FBSL has it all intrinsically, however SB's POW(n) is in fact POW10(n) only);
-- division functions: modulo and remainder;
-- rounding functions: floor (as it should be, not as it is now), ceiling, round, truncate, and abs (FBSL has them all intrinsically, not sure about SB).

Language extension iterators of the (do) and named let kind will come after the basic functionality above has been implemented in the BL vocabulary.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 24, 2014, 12:49:32 AM
Hi Rob,

Thank you very much for this additional info. It makes things a little clearer and better ordered in my lamer's mind.

Quote
It may be the pure no-library "syntax" refers to the original Sussman / Steel / etc experiment which I think contained no loop mechanism and in those days was named Schemer - but personally I never would use such , unless in a masochistic mood.

Hehe, no need to go that far. I'll try to add the three iterative features that you described above (in fact, tail recursion is already there with an explicit lambda keyword and one extra pair of parentheses) as soon as I'm through with the yet-missing basic features that I enumerated in my prior post.

Keep the faith! :D
Title: Re: Lisp in Basic
Post by: RobbeK on August 24, 2014, 01:08:16 AM
Thanks Mike  ;)

Digging deeper :

Intuitively, no space is needed for an active tail call because the
continuation that is used in the tail call has the same semantics
as the continuation passed to the procedure containing the call.
Although an improper implementation might use a new con-
tinuation in the call, a return to this new continuation would
be followed immediately by a return to the continuation passed
to the procedure. A properly tail-recursive implementation re-
turns to that continuation directly.
Proper tail recursion was one of the central ideas in Steele and
Sussman’s original version of Scheme. Their first Scheme in-
terpreter implemented both functions and actors. Control flow
was expressed using actors, which differed from functions in
that they passed their results on to another actor instead of
returning to a caller. In the terminology of this section, each
actor finished with a tail call to another actor.
Steele and Sussman later observed that in their interpreter the
code for dealing with actors was identical to that for functions
and thus there was no need to include both in the language.
A tail call is a procedure call that occurs in a tail con-
text. Tail contexts are defined inductively. Note that a tail
context is always determined with respect to a particular
lambda expression.

---

IMO the (do ) macro can be written, but only of the Scheme contains the quasiquote and the mechisms it is working together, this belongs the (pure) "syntax"

4.2.6. Quasiquotation
(quasiquote hqq templatei) syntax
`hqq templatei syntax
“Backquote” or “quasiquote” expressions are useful for
constructing a list or vector structure when most but not
all of the desired structure is known in advance. If no
commas appear within the hqq templatei, the result of
evaluating `hqq templatei is equivalent to the result of
evaluating ’hqq templatei. If a comma appears within
the hqq templatei, however, the expression following the
comma is evaluated (“unquoted”) and its result is inserted
into the structure instead of the comma and the expres-
sion. If a comma appears followed immediately by an at-
sign (@), then the following expression must evaluate to
a list; the opening and closing parentheses of the list are
then “stripped away” and the elements of the list are in-
serted in place of the comma at-sign expression sequence.
A comma at-sign should only appear within a list or vector
hqq templatei.

and this in combination with :
(let-syntax hbindingsi hbodyi)   syntax

(in combination with syntax-rules ..  I think John already gave the do - maco ; however this syntax is missing here .

best Rob
Title: Re: Lisp in Basic
Post by: JRS on August 24, 2014, 01:12:10 AM
Excellent progress Mike with BL. I'm really liking where this is going!

I can't wait until Charles gets O2 in the ball game.

 
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 24, 2014, 02:40:46 AM
Quote
Quote
... whenever a function calls itself in such a way that the same effect can be implemented by a loop or iteration, Scheme guarantees that the compiler will rewrite it to a loop at the machine-code level, so you will never run out of stack space or need useless time to call procedures when what you try to do can be rewritten to a loop ...
Mike:
(Rob and Charles, I wonder what the algorithm may look like to programmaticaly analyze a Scheme recursive procedure and unroll/fix/recode it automatically into a loop?)

Once a tail recursion is identified, set the params using temp variables as intermediates. Then goto start of the function's inner code body, accumulating the loop results.

O2 Fibo Example:
Code: [Select]
'TAIL RECURSION
===============

function fibo(m,n,c) as string
if c
  return n+" "+fibo(n,m+n,c-1)
end if
end function


'TRANSLATE TO LOOP
==================

function fibo(m,n,c) as string
recur:
if c
  'PARAM SETTING
  tc=c-1 : tn=m+n : tm=n
  m=tm : n=tn : c=tc
  function += n+" "
  goto recur
end if
end function


print fibo 1,1,10
Title: Re: Lisp in Basic
Post by: RobbeK on August 24, 2014, 02:53:20 AM
Thanks Charles,

The Ascii Mandelbrot in BL

----------------------------------------

(define grid '())
(define mapped-grid '())

(define modulus
  (lambda (n d)
     (let (( r (floor (/ n d))))
      (- n (* r d)))))

(define cadr
    (lambda (L)
      (car (cdr L))))

(define sqrt
     (lambda (x)
       (exp (/ (log x) 2))))

(define sq (lambda(x) (* x x)))

(define 1- (lambda (x) (- x 1)))
(define 1+ (lambda (x) (+ x 1)))

(define level
 (lambda (i x y rc ic it orb)
  (if (or (= i it) (> orb 4)) i
    (level (1+ i) (+ rc (- (sq x) (sq y))) (+ ic (* 2 x y)) rc ic it (+ (sq x) (sq y))))))

(define mlevel
   (lambda (L)
     (level 0 (cadr L) (car L) (cadr L) (car L) 11 0)))

(define fill-grid
   (lambda (nrx xo dx nry yo dy matrix dup)
       (if (and (= 0 nrx) (= 0 nry)) matrix
         (if (= 0 nry) (fill-grid (1- nrx) xo dx dup yo dy matrix dup)
           (fill-grid nrx xo dx (1- nry) yo dy
            (cons (list (+ xo (* nrx dx)) (+ yo (* nry dy))) matrix) dup)))))

(define square-grid
   (lambda (nr x y dz)
     (fill-grid (1- nr) (+ x dz) dz nr y dz '() nr)))

(define map-grid
   (lambda (L)
     (map mlevel L)))

(define print*
  (lambda (x)
    (if (> x 9)
      (print x)
      (sequence (print x) (print '" ")) )))

(define print-grid
   (lambda (i it L)
     (if (null? L) T
       (if (= i it) (sequence (print* (car L)) (newline) (print-grid 0 it L))
         (sequence (print* (car L)) (print-grid (1+ i) it (cdr L)))))))

(define main
  (lambda ()
    (set! grid (square-grid 30 -1.7 -2.3 0.1))
    (set! mapped-grid (map-grid grid))
    (print-grid 0 30 mapped-grid)
))

--------------------------------  modulus, and sqrt are not used , they may be removed -----------

any other Ascii "layout" can be done without much effort now ...  the iteration level is decoded in (print* )
..

progr does : makes a grid of coordinates ,  maps the Mandelbrot on every coordinate , makes a grid with the resulting iteration values - prints this list following print* directives ..

best Rob



.
Title: Re: Lisp in Basic
Post by: JRS on August 24, 2014, 07:46:50 AM
That's very cool Rob!

Much faster than I was expecting. When it didn't display anything at first, I was ready to head out for a coffee break and before I could get up from my chair the Mandelbrot displayed. This should make Mike happy!

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp/Rob$ time scriba lisp.sb asciiM.bl
SBLisp - Scheme BASIC Lisp

(define grid '())
GRID
(define mapped-grid '())
MAPPED-GRID
(define modulus
  (lambda (n d)
     (let (( r (floor (/ n d))))
      (- n (* r d)))))
MODULUS
(define cadr
    (lambda (L)
      (car (cdr L))))
CADR
(define sqrt
     (lambda (x)
       (exp (/ (log x) 2))))
SQRT
(define sq (lambda(x) (* x x)))
SQ
(define 1- (lambda (x) (- x 1)))
1-
(define 1+ (lambda (x) (+ x 1)))
1+
(define level
 (lambda (i x y rc ic it orb)
  (if (or (= i it) (> orb 4)) i
    (level (1+ i) (+ rc (- (sq x) (sq y))) (+ ic (* 2 x y)) rc ic it (+ (sq x) (sq y))))))
LEVEL
(define mlevel
   (lambda (L)
     (level 0 (cadr L) (car L) (cadr L) (car L) 11 0)))
MLEVEL
(define fill-grid
   (lambda (nrx xo dx nry yo dy matrix dup)
       (if (and (= 0 nrx) (= 0 nry)) matrix
         (if (= 0 nry) (fill-grid (1- nrx) xo dx dup yo dy matrix dup)
           (fill-grid nrx xo dx (1- nry) yo dy
            (cons (list (+ xo (* nrx dx)) (+ yo (* nry dy))) matrix) dup)))))
FILL-GRID
(define square-grid
   (lambda (nr x y dz)
     (fill-grid (1- nr) (+ x dz) dz nr y dz '() nr)))
SQUARE-GRID
(define map-grid
   (lambda (L)
     (map mlevel L)))
MAP-GRID
(define print*
  (lambda (x)
    (if (> x 9)
      (print x)
      (sequence (print x) (print '" ")) )))
PRINT*
(define print-grid
   (lambda (i it L)
     (if (null? L) T
       (if (= i it) (sequence (print* (car L)) (newline) (print-grid 0 it L))
         (sequence (print* (car L)) (print-grid (1+ i) it (cdr L)))))))
PRINT-GRID
(define main
  (lambda ()
    (set! grid (square-grid 30 -1.7 -2.3 0.1))
    (set! mapped-grid (map-grid grid))
    (print-grid 0 30 mapped-grid)
))
MAIN
(main)
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 1
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2 2 1
1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2 2 1
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3 2 1
1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3 3 1
1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3 3 1
1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3 3 1
1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3 3 1
1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4 3 1
1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4 3 1
1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4 3 1
1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4 3 1
1 1 1111111111111111111111111111111111111111111111117 5 4 3 1
1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4 3 1
1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4 3 1
1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4 3 1
1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4 3 1
1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3 3 1
1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3 3 1
1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3 3 1
1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3 3 1
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3 2 1
1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2 2 1
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2 2 1
1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 1
1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 T
(quit)

real 0m35.469s
user 0m35.406s
sys 0m0.028s
jrs@laptop:~/sb/sb22/sblisp/Rob$
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 24, 2014, 08:38:12 AM
This is REALLY COOL! :D

Rob, thanks A LOT! I'll be back with my update on the progress later on tonight.

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 24, 2014, 08:48:48 AM
Hi Charles,

Once a tail recursion is identified, set the params using temp variables as intermediates. Then goto start of the function's inner code body, accumulating the loop results.

Will this algo apply to any tail recursion case imaginable? Of any complexity and nested depth so that pattern recognition and unrolling can be automated?
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 24, 2014, 10:29:21 AM
Mike,

Complexity is okay as long as it results in single level tail recursion, but other formats could be supported, if the system is smart enough to detect them:

for instance, alternative conditions tail recursion:

function f(...) as ...
if ...
  return f(...)
elseif ...
 return f(...)
else
  ...
end if
end function
Title: Re: Lisp in Basic
Post by: JRS on August 24, 2014, 10:50:42 AM
This is where BL needs to be. IMHO

Code: [Select]
(load-extension "tsx_mysql")

(display "Mysql extension test.")(newline)

(define queries (list
                  "SELECT VERSION(), CURRENT_DATE"
                  "SHOW DATABASES"
                  "SELECT  table_name, table_type, engine FROM information_schema.tables"))

(define run-query
  (lambda (sql)
    (let ((result (mysql-query sql)))
      (if result
        (display result)
        (display (mysql-error))))
    (newline)))

(if (mysql-connect "" "" "" "")
    (for-each run-query queries)
    (display (mysql-error)))

(mysql-disconnect)
(newline)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 24, 2014, 01:02:41 PM
So here comes my report on the current state of affairs in the BL project.


0. What I wanted to do and why:

0.1. I wanted to de-interleave the GOTO/GOSUB code into SUB's and/or FUNCTION's to eliminate the necessity to count the current stack depth in every program step. Stack depth counting is required to be able to unwind the stack in case the interpreter hits an exception and needs to be reset in its initial state recovering its program stack from the state of deep recursion and/or deeply nested mutual calls. If the stack is left unwound, its uncontrolled growth may lead to its eventual exhaustion and total program crash.

0.2. The existing strategy of stack depth counting however isn't a panacea. Even if the stack is unwound successfully and the interpreter is reset to its initial state, in very many cases there is no possibility to correct the faulty LISP code already entered for execution. If the faulty code is a simple immediate arithmetical expression, it can be re-entered with all the typos corrected and re-run again. But now let's assume that we entered the definition of a complex lambda successfully, the syntax checker hasn't found any lexicographical errors, and the lambda name has been added as a SYMBOL to the symbol hash table. At run time however the lambda may cause an exception e.g. due to improper math calc hardcoded in it. The interpreter will be reset but the lambda cannot be recoded because its SYMBOLic name cannot be redefined in the hashtable. BL doesn't support redefinition of its SYMBOL's. It can be fully reset only by quitting the current session altogether. It makes the entire headache of counting the stack depth not worthwhile.

0.3. There are over 550 instances of BSD (stack depth counter) incrementation throughout the code corresponding to GOSUB calls, and there will be an exact same amount of decrementations to keep the stack balanced. And all this in just one single cycle without going into any recursion or a nested call whatsoever. Going recursive will increase these numbers many times over. It means we will be executing many thousands of incrementations and decrementations over and over again for a slim chance of unlikely error in a piece of known working code. This will be a speed killer for any interpreter even if it runs compiled to machine code, e.g. like OxyLISP will.


1. What I did:

1.1. I thought that natural early bailout from functions in response to an error will keep the stack balanced equally well without any artificial stack depth counting. So I tried to de-interleave the existing GOTO's and GOSUB's into more structured SUB/FUNCTION code entirely. But I was able to do so without breaking the expected program flow only to some two fifths of the total amount of program code. The entire LispEval refuses splitting into functions no matter what I do because the expected program flow gets broken whenever the error is raised in anything more complex than a simple arithmetical operation.

1.2. I became convinced that adding continuous error flag checks and assigning return values to functions may lead to overhead penalties as severe as those caused by continuous BSD incrementation and decrementation. The interpreter will stay just as slow with functions as it was with the stack depth counter.

1.3. Based on my findings and considerations as per Items 0.2 and 0.3, I reverted the entire code to its initial GOTO/GOSUB state and deleted the BSD counter altogether. In doing so I expect that infrequent typos in the interactive input of simple math one-liners will not eat up the stack to any visible amount while major mishaps like those described in Item 0.2 will require the user's univocal exit from the current session.

1.4. I added a command line option -q (quit session on error) to let the user to either proceed as per Item 1.3 or force the interpreter to quit the current session immediately on the first error encountered. The option works in both interactive and file-load-and-run modes but seems more practical in the latter.


2. What I'm planning to do:

2.1. The initial QB functionality with BSD can be fully re-implemented in Oxygen with Charles' ReturnLabel inline asm trick but OxyLISP will suffer speed penalties as described in Item 0.3. We should seriously reconsider these consequences before we proceed that way.

2.2. The initial QB functionality can be fully re-implemented in SBLisp when it is rewritten in CBASIC. We can use Charles' trick emulated with GCC's inline assembly too but only to suffer the exact same unjustified penalties. GOSUB/RETURN functionality can also be emulated with the aid of GCC's inline assembly.

2.3. FBSL's DynC does not support inline assembly of its own therefore Charles' trick can't be used in FBSL at all. FBLisp will stay as per Items 1.3 and 1.4 even in its DynC implementation. FBSL can do it all as well in both its BASIC and DynC variants.

2.4. I suggest we consider the current state of BL code as the final prototype before getting down to the actual implementation in each respective language.

2.5. I propose OxyLISP and O2 as the first step of BL implementation in each language. O2 with its "strongly elastic" arrays is easier to work with than pure ANSI C or CBASIC and OxyLISP will immediately show us what we may expect from DynC and moreover, from fully optimized -O3 GCC, later.


3. What I'm currently doing:

3.1. I'm currently working in FBSL with FBLisp.

3.2. I've added a -h option to display a brief usage and option help screen.

3.3. I've changed -d to -v (verbose) to display extended error messages and LISP code as it is being loaded from the disk file. Without that option, BL displays only loaded SYMBOL names (as Rob said) and short error descriptions as it did before. You can see Rob's ASCII Mandelbrot loaded into my FBLisp without the -v switch in my latest screenshot.

3.4. I've added trig and rounding mode functionality. OxyLISP can use msvcrt.dll API's. If something is missing in SB, I'll add #unimplemented stubs for the time being. They will be changed for GCC's intrinsics when ported to CBASIC/GCC for final compilation. This way OxyLISP, SBLisp and FBLisp's LISP scripts will fully compatible until/unless language specific add-ons are developed and added in the future.

3.5. When I'm through with pow and division functions, I will post the FBSL sources here for examination (they are easy to read in the two other languages too), and a precompiled FBLisp binary for testing.

Dixi.  8)

UPD Charles inspired me to make one last attempt at restoring BL's program stack properly. This time I succeded, therefore the lines that are striken through above no longer apply. BL will handle its stack just as good as Lisp-in-Basic did, but more efficiently and visibly faster. :)
Title: Re: Lisp in Basic
Post by: JRS on August 24, 2014, 01:24:08 PM
Quote
I will post the FBSL sources here for examination ...

 :(  I thought you were using SB for the prototype of BL. Why the switch to FBSL? Did I waste my time with the SB / Bitbucket effort? I'm not participating in a Windows only project. Sorry!



Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 24, 2014, 03:40:00 PM
Preconception? Jealousy? How fast you are jumping to conclusions! ::)

1. I am able to prototype this particular code in SB almost as fast as in FBSL, but...

2. I had only an early FBSL proto at hand that would contain all the initial GOTO's and GOSUB's in it, reformatted but fully QB-based. So my decision was only too natural under the circumstances. Nothing personal, just business.

3. Actually I was planning to port my FBSL proto to SC to be tried under Linux too while you were still alpha testing the proto under Wine and Win 7. Who told you it will stay Windows only? And Rob doesn't care, in the meantime, if it's SBLisp.exe or FBLisp.exe that he's using for his fine art so long as its functionality is exactly the same. In this manner, you won't be sitting with nothing to do while I'm porting the proto to SB.

So what's all this buzz about? Am I jealous of your adultery with ECL or TinyScheme? No. So why are you jealous of me and my FBSL? Perhaps because that's what you would have done in my place -- trash FBSL and hurry on with your SB? That's not my style, John. I said I care for, and am taking care of, all the three implementations BL in the respective languages with equal concern.

So you have nothing to be sorry about. All sorrow is mine again, not yours.

Shame on you, John. Never thought your reaction would be so inadequate. I'm feeling like someone has just spat in my face despite all the work I've done...

Go ahead with your TinyScheme exercises.



Good night.

Title: Re: Lisp in Basic
Post by: JRS on August 24, 2014, 04:02:18 PM
I'm just trying to follow along based on your mixed messages and demands. You said to freeze the SB code as your were going through a major revision. While on the bench, I was drafted by the TinyScheme team. :P The next thing I hear is a FBSL version will be posted shortly with source which you have forbidden to reside anywhere other than the FBSL site. Preconception? Jealousy?  I think you are reading between the lines. BASIC Lisp is interesting and fun project because it gives us an opportunity to see how a Lisp runs under the covers and actually understand what is going on.

Please let me know when you have a working SB version so I can update the repository and unfreeze the code.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 24, 2014, 04:27:59 PM
I'm just trying to follow along based on your mixed messages and demands.

From now on, you won't be getting messages from me in order to avoid mixing them with some other LISP's that you're trying to master. Neither will there be any demands or requests or suggestions addressed to you personally. Nor will there be any reports on what I did, or what, why and how I'm planning to do, or actually am doing. None of all that crap any more. Delivery terms on board ship O2 forum, payment at sight. No more fooling around.

Quote
Please let me know when you have a working SB version so I can update the repository and unfreeze the code.

You will get to know it automatically having seen it uploaded here just as its FBSL and O2 counterparts.

No need to see me off, John. Have a good day.
Title: Re: Lisp in Basic
Post by: JRS on August 24, 2014, 04:28:33 PM
Good night and sleep well.

Once again, thanks for all the effort you have put into the BL project.
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 24, 2014, 05:00:56 PM
Mike,

It seems to me that error bail-outs cause a lot of complication in the Lisp engine, particularly in managing the stack. Have you considered using a run-time error log instead? The standard behaviour would then be to log the error and its position, then exit the current function and continue operations normally. The program would then be able to check its error log at an appropriate point, and respond under full program control.

I also have some further thoughts on tail recursion in functions involving strings. Local garbage collection and local string clearing have to be woven into the algorithm converting tail-recursions into loops.
 
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 25, 2014, 01:37:38 AM

A model for direct-string-safe tail-recursion:

rather intense for a compiler :)

Code: [Select]
'ORIGINAL
=========

function fiboR(m,n,c, string s) as string
if c
  return n+" "+fiboR(n,m+n,c-1,s)
end if
end function


'TRANSLATE TO LOOP
==================

function fiboL(sys m,n,c, string _s) as string 'DECORATE DIRECT STRING PARAMS
'
bstring s=_s      'MAKE COPIES OF ALL DIRECT STRING PARAMS
bstring recurn    'RETURN VALUE (now a bstring)
recur:            'LOOP POINT
                  'START OF SOURCE FUNCTION BODY
if c              '
  recurn += n+" " 'ACCUMULATE RETURN VALUE (instead of return ...)
                  '
                  'PARAM SETTING (safe!)
  tc=c-1 : tn=m+n '
  tm=n : ts=s+"X" '
  m=tm : n=tn     '
  c=tc : s=ts     '
  lea edi,[ebp-4] 'LOCAL GARBAGE COLLECTION LIST
  call [ebx+2080] 'DELETE LOCAL STRINGS (RTL:delchain)
  goto recur      'MAKE RECURSIVE LOOP
end if            '
                  'END OF SOURCE FUNCTION BODY
frees s           'RELEASE ALL COPIES OF DIRECT STRING PARAMS
return recurn
end function

'print fiboR  1,1,10,"dummy"
 print fiboL 1,1,10,"dummy"
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 25, 2014, 01:46:29 AM
Hi Charles,

It stands to reason to try what you suggest. Basically there are three linear steps in each interpreting loop cycle: lispread (keyboard input or file line), lispeval, and lispprint.

Lispread in its file line hypostasis can go down one level into its own lispread, lispeval and lispprint loop where low-level lispread, lispeval and lispprint behave exactly like those in the top-level main loop, i.e. can go down yet further.

Lispeval can go down into yet another lispeval and lispprint.

Lispprint can only go down (recurse) into itself.

Each lispread, lispeval and lispprint can call about five dozen helper subs some of which can also call lower-level lispevals of their own. Each of these subs can log various errors and signal them by setting a global error flag.

My earlier designs tried to respond to the error flag with immediate bailout from whatever sub the code pointer currently was in. It flooded the code with innumerous error flag checks upon exit from almost any sub call in the code. I was getting rid of 550 incrementations of stack counter just to find myself in some 500 checks of global error flag instead. Traded bad for worse, so to speak.

Bailing out immediately was supposed to bring me very quickly back to the top-level (main) loop unwinding the stack all along but doing actually nothing else in the process. Is that correct strategically? I think yes. But actually it didn't work no matter what I did.

So now I have removed the error flag and all the checks altogether. Instead, I suggest complete program exit on an error condition because even if the scheme worked, I wouldn't be able to correct mistakes in the input in most cases because BL does not allow me to fix up and redefine (re-enter) badly defined symbols (mostly lambdas).


Epilog:

I think I can only have one last try. I will reinstate the error flag but I will only bail out in response to it at the first line of just three major subs -- lispread, lispeval, and lispprint -- all other subs ignoring the current error state. It may prevent any deeper recursion in case of an error and cause actual surfacing in the main loop hopefully without running into a seg fault in some helper sub in the process.

I'll report my findings here. But if it doesn't help, I do not see any other way out except just quit on any error.


UPD My last attempt was successful. My words above that have been crossed out no longer apply. And I'm pretty happy with it. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 25, 2014, 01:59:06 AM
Charles, :)

A model for direct-string-safe tail-recursion:

You are posting wonderful things here indeed. But all of them are head- and hand-crafted by your personal human analysis of recursive fibo function. I think it would be a much greater challenge to program an AI routine to automatically recognize recursive patterns by certain criteria and automatically regroup them into iterative sequences. Such a routine would be in fact the Scheme compiler as it was described in that quotation from Scheme description on the net.

By the way, such policy looks like conspiracy and cheating to me. First they mesmerise you into twisting your brain with laborious recursive designs which would in fact be turned automatically into clean, simple, fast and easy to write iterative code. Isn't it what we would call fraud, do you think? :D
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 25, 2014, 02:24:46 AM
I suppose it is a misconceived attempt at mathematical purity. Recursion is vital for certain tasks such as expression analysis, but it is perverse to use it for simple iteration.
Title: Re: Lisp in Basic
Post by: Aurel on August 25, 2014, 04:23:44 AM
Mike ..
this is exellent explanation..
Quote
0.3. There are over 550 instances of BSD (stack depth counter) incrementation throughout the code corresponding to GOSUB calls, and there will be an exact same amount of decrementations to keep the stack balanced. And all this in just one single cycle without going into any recursion or a nested call whatsoever. Going recursive will increase these numbers many times over. It means we will be executing many thousands of incrementations and decrementations over and over again for a slim chance of unlikely error in a piece of known working code. This will be a speed killer for any interpreter even if it runs compiled to machine code, e.g. like OxyLISP will.

Hmm..may i ask you something...
i have in plan to add in my small ruby-truby interpreter SUBS/FUNCS
do you can suggest me the best way (i mean speed wise) what i must do?
i see that you talk that stack is not best option ( i was used in AB ordinary array as stuck
which hold SUB positions)
thanks in advance
Aurel

/ps i would like to see FBSL code about that because looks more natural to me than SB/
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 25, 2014, 04:32:06 AM
Charles,

BASIC Lisp is now working like a Swiss watch. 78 carefully placed IF eflag THEN RETURN commands have just done everything that was formerly done by over 550 bsd += 1 and over 160 bsd -= 1 commands in Arthur's original code. And no need for the ReturnLabel asm hack any more. The entire code will stay built around GOTO/GOSUB/RETURN commands.

Thank you very much indeed for having inspired me to make this very last attempt. It worked.

I have just proudly written your name into the list of credits in the FBLisp info blurb.

:D
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 25, 2014, 04:43:08 AM
Hi Aurel,

We are talking here about BASIC's process stack, not the "stack" of LISP code interpreter. LISP's "stack" is implemented in BL as a set of arrays similar to what you have in your own interpreter.

The fastest way for a program to work will be to have all its variables defined as globals, and all its program flow implemented with the old-skool GOTO and GOSUB/RETURN commands. They will be resolved by OxygenBasic directly to JMP and CALL/RET instructions, respectively. Genuine SUB/FUNCTION calls would lead to heavier penalties, speed-wise.

I will post the FBSL code and executable here very soon. Please wait a little and you'll have what you're asking for. :)
Title: Re: Lisp in Basic
Post by: Aurel on August 25, 2014, 05:09:18 AM
ok Mike i will wait...and thanks!
 ;)
Title: Re: Lisp in Basic
Post by: Charles Pegge on August 25, 2014, 05:25:20 AM
Thanks Mike,

We must find some interesting things to do with all this LISP. I am inclined to use it for high level tasks which are cumbersome in BASIC, but delegate all the hardcore graphics and API work to BASIC functions. Will your implementation work as part of such a hybrid?

PS: I think classical globals, gosub and goto are beneficial in the context of a compiler or interpreter. O2 uses some 250 global state variables, which is perfectly manageable. LeanLisp uses only 18 so far!
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 25, 2014, 06:09:06 AM
Charles,

As long as OxyLISP and FBLisp (re-written in DynC) stay as include files for other projects, they can interact easily with other parts of the project programmatically as soon as we add a LISP command that would allow BL to run LISP code from memory rather than keyboard or file only, and provide the corresponding returns to the BASIC caller. I hope there is some such standard command in the Scheme vocabulary. Also, OxyLISP and FBLisp can enjoy in their engines whatever the respective BASIC's have to offer natively, for example, graphics.

This isn't however the case with SBLisp. It can't stay as is in this interpretative form as an include file because it will be too slow. So it must be re-written in C either directly or via CBASIC and compiled as a dynamic library extension. Then it will be able to communicate with its SB host via the same exec-from-memory mechanism but it will have to have its own intrinsic bindings to the other SB luxuries such as e.g. SB's IUP graphics.

Or SBLisp can stay as a CBASIC or C include file for C-based SB projects where SB is used as an embeddable engine. Then it could enjoy common resources, e.g. IUP graphics again, that have their bindings with such a C language based project as a whole.

I don't see any reason why it shouldn't or couldn't be done like that. :)
Title: Re: Lisp in Basic
Post by: JRS on August 25, 2014, 10:06:26 AM
Quote
This isn't however the case with SBLisp. It can't stay as is in this interpretative form as an include file because it will be too slow. So it must be re-written in C either directly or via CBASIC and compiled as a dynamic library extension. Then it will be able to communicate with its SB host via the same exec-from-memory mechanism but it will have to have its own intrinsic bindings to the other SB luxuries such as e.g. SB's IUP graphics.

Or SBLisp can stay as a CBASIC or C include file for C-based SB projects where SB is used as an embeddable engine. Then it could enjoy common resources, e.g. IUP graphics again, that have their bindings with such a C language based project as a whole.

I don't see any reason why it shouldn't or couldn't be done like that.

Hi Mike,

Sounds like interesting and exciting stuff going on with the BASIC Lisp project. Just to be clear, the SBLisp version initially was done as an exercise to see how QB compatible SB might be. I would like to see the SBLisp version be used as a prototyping tool for Scheme and a teaching aid. As you said many times, this phase of the project is about functionality and stability. Speed would come later. If you have time to keep the SB version current with your efforts in BL, that would be great. I have no plans converting it to C BASIC or making an ext. module out of it. I'm very happy with TinyScheme as it was designed from the ground up as an embeddable small footprint Lisp scripting engine.

Let me know if there is anything I can do to help the BASIC Lisp project along.

John
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 25, 2014, 11:31:19 AM
Hi John,

Thanks for making me aware of your decision. If it is definitive then I will confine myself exclusively to updating SBLisp to the current functionality of FBLisp proto and uploading it here. Then I will proceed with the development of FBLisp and OxyLISP only.

I am glad you have finally made your choice. There is nothing much left to do with the proto so I think I will be able to finalize it myself. Thanks for offering help though.

Mike

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 25, 2014, 11:41:16 AM
Charles and Rob,

How would you comment on this flagrant contradiction between C, O2 and FBSL maths, on the one hand, and Scheme math, on the other? The second snapshot is taken from the r6rs standard of the Scheme language.

Please note that Scheme's remainder behaves exactly like our beloved mod whereas if I implement my own remainder for BL as I understand it should work, it will behave exactly like Scheme's modulo.

Please advise what I should do. I am totally confused and baffled... :o

.
Title: Re: Lisp in Basic
Post by: RobbeK on August 25, 2014, 11:59:58 AM
Hi Mike ,

The showed results are exact for Lisp -- they are based on (floor ) which "truncates" towards negative infinity , while (truncate ) "truncates" towards zero.   I think you already made a comment on (floor ) and (ceiling ) pointing at this oddity (?)

best, Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 25, 2014, 12:07:51 PM
Rob,

Should I understand your answer as an indication that I should follow the r6rs standard and just make the BL users aware that Scheme's modulo is not the same as C/BASIC mod?

If so then I will be using BASIC mod as remainder in BL and I will add my own code as BL's Scheme-compatible modulo.

Is that correct?



P.S. And what concerns rounding modes floor, ceiling, round, truncate and abs: I made them behave exactly as per r5rs/r6rs standards. I'm currently following the r5rs standard which defines what is called Scheme's core language as opposed to everything else that's been added in r6rs as library extensions.

Luckily do, begin and named let do fall into the r5rs frame of core language vocabulary, whereas while and others aren't included in it.
Title: Re: Lisp in Basic
Post by: RobbeK on August 25, 2014, 12:23:09 PM
Hi Mike,

Yes, that seems a sensible solution -- it should be clearly explained in the documentation , &  both Lisp & C/Basic users should be satisfied this way imho.

best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 25, 2014, 12:26:22 PM
Understood. I will follow your advice.
Title: Re: Lisp in Basic
Post by: RobbeK on August 27, 2014, 05:16:12 AM
Hi all,

Also posted under TinyScheme - Open Forum.
Smart solutions : to speed up things a memoizing table is made , the one posted on TinyScheme contained 1000 "anchor - points" , here 500 , but that's about the limit for the NewLisp stack. (i mean for double recursive calculations)

The memo table is set up in blocks of 200 using it previous memoized result.
A sample with n!  (writes easier , but it's the same)
p.e. 10! is memoized , and then 20! becomes 20*19*...*11*10!   etc...   calculations are done exactly the same way -- it calculates till a memoized value is encounterd (max 199 thus in this case).
It should also show the compactness and power of Lisp --  (memoize   ) is written as a macro and can be applied on any definition

best Rob  (one remaining problem : every entry will set up a new memo anchor --  needs unmemoize then I think  8)

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 29, 2014, 05:47:55 AM
Hi Rob,

What you posted is a very nice example of using a table of cached values. I submitted another example here (http://www.oxygenbasic.org/forum/index.php?topic=1147.msg10887#msg10887) based on the C code that John had posted earlier.

We simply didn't know at that time that LISP's caching is called memoization. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 29, 2014, 06:01:13 AM
Hi all,

I'm here just to let you know that I'm safe and sound. I'm still working on the BL proto making it more Scheme-compliant. Much has been done but one major improvement is still pending.

Arthur's Lisp-in-Basic is a command line interpreter that re-parses and re-evaluates each line whenever it is entered via a keyboard or read from the program memory. It also re-computes its hash table indices for each token it finds in such a command or program line again and again. This is the simplest and the least efficient implementation of an interpreter. In this regard Lisp-in-Basic is much poorer even than Ed's Toy interpreter.

I'm currently adding a very basic bytecode compiler to it that I hope can make it up to an order of magnitude faster even in its prototype form. Regardless of my success of failure in that attempt, I'm planning to post the proto only after I'm through with my investigations.

See you again later. Just stay tuned. :)
Title: Re: Lisp in Basic
Post by: JRS on August 29, 2014, 08:35:31 AM
Quote
I'm here just to let you know that I'm safe and sound.

Glad to see you're doing okay. Starting to wonder where you were. Thanks for the BASIC Lisp update. I'm looking forward to see the SB version of your efforts.

Title: Re: Lisp in Basic
Post by: RobbeK on August 30, 2014, 03:06:24 AM
Hi Mike,

Nice to read you  :)

the Ackermann  --  yep, let's find a way to destroy it ...   8)

best Rob
Title: Re: Lisp in Basic
Post by: RobbeK on August 30, 2014, 03:26:58 AM
Mission accomplished :


 8)

"I come to bury the Ackermann, not to praise him."     from Shakespeare's Julius Caesar (more or less  ::)

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 30, 2014, 11:21:28 PM
Mission accomplished : 8)

No way Rob,

Your exe says it needs some funky libreadline.dll library and quits. :(
Title: Re: Lisp in Basic
Post by: JRS on August 30, 2014, 11:55:15 PM
That explains why it didn't run under Wine either.  :'(
Title: Re: Lisp in Basic
Post by: RobbeK on August 31, 2014, 01:40:25 AM
OOps -  :-[

forgot CLisp needs some DLLs to run ,

-- bundled it into a GCL executable ....


best , Rob

it runs in interpreted mode , if you type (compile 'ackermann) it will compile the function -- (main) runs it in compiled mode then.
...  and then (time (main))   will give the time spent to run ....

also added mandelmemo -- An output from the  STALIN Scheme compiler

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on August 31, 2014, 05:43:04 AM
Hi Rob,

1. Is this an interpreted Ackermann code?!

It is blazing fast nor does it cause inevitable stack exhaustion at [4,2]. It must be turned transparently into its iterative equivalent else it isn't really possible... :o

2. Your graphic mandel is beautiful. :)

3. What are LISP "environments"? Are these what we call variable visibility scopes in plain English? (similar to how "memoization" is nothing but good 'ole cache...)
Title: Re: Lisp in Basic
Post by: RobbeK on August 31, 2014, 11:49:46 AM
Hi Mike,

1) Yes, interpreted , but comes with a note :  tail-recursive call to ACKERMANN converted to iteration (it also uses caching , of course).
at the command line when the demo ends, you can do   (compile 'ackermann) , you will see same message pops up again....

2) interesting experiment -- the idea is to memoize/cache 2D area's   -- this is how it looks with a (infantile) low table (only 800*800 = the number of pixels used )   -- I may can get reasonable results with a table of 3*3*10000*10000 floats -- this prog is NOT done by caching , it just simulates the result with a small table.  (the problem is, things like fibonacci , x! , Ackermann are exact numbers , the outcome of a Julia iteration is not -- somewhere we have to declare non identical numbers but close numbers equal to make it working .  Nevertheless, imo the result is attractive.   

3)  yes & yes , it's much easier to invent new names than new techniques ;-)
About a decade ago, caching also entered computer chess  ,  prototyped by Налимов   

https://ru.wikipedia.org/wiki/%D0%AD%D0%BD%D0%B4%D1%88%D0%BF%D0%B8%D0%BB%D1%8C%D0%BD%D1%8B%D0%B5_%D1%82%D0%B0%D0%B1%D0%BB%D0%B8%D1%86%D1%8B_%D0%9D%D0%B0%D0%BB%D0%B8%D0%BC%D0%BE%D0%B2%D0%B0


Look how much is needed for 7 "figures"  ---  (the English version doesn't give these numbers, it seems - from there the link above)   -- it will not kill the game of chess ,   possible combinations at the start of a game may be something of (the reward of the King) !     8)    (faculty of the number of grains at field 64 )

best Rob

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 09, 2014, 11:17:09 PM
Guys, you won't believe it but what you're seeing in the appended snapshots is the birth of FBSL's brand new JIT compiling DynLisp layer. It's at its proto stage yet and it can do just a few Lisp operations only but it can already resolve a recursive lambda.

See how it beats Tiny Scheme in calculating (fibonacci 35) -- it's exactly 90 times faster. I wouldn't post this message in the TS thread for fear lest henceforth John redard me his personal archenemy for sabotaging his own SB extension. :D

I'm feeling very excited and I just wanted to share my feelings with you.

.
Title: Re: Lisp in Basic
Post by: RobbeK on September 10, 2014, 12:26:29 AM
Congrats, Mike ...   ;)

It would be interesting to see the benchmark with a helper (single) recursive function :

(defun fibo*  ( a b x)
    (if (= x 0) a
        (fibo* b (+ a b) (1- x))))

(defun fibo (x)
   (fibo* 1 1 x))

;; needs to be converted into Scheme syntax

-------------------------------------------output from the REPL , CLisp in interpreted mode :


[4]> (time (fibo 35))

Real time: 0.0 sec.
Run time: 0.0 sec.
Space: 12 Bytes
14930352
[5]> (time (fibo 350))

Real time: 0.0 sec.
Run time: 0.0 sec.
Space: 8496 Bytes
10119911756749018713965376799211044556615579094364594923736162239653346274
[6]>
[6]> (time (fibo 3500))

Real time: 0.046875 sec.
Run time: 0.046875 sec.
Space: 566808 Bytes
GC: 1, GC time: 0.03125 sec.
2071302422030262753416199537299341464207691967344600973326088247223853841292493160797697343340451944
4976593116933291600999770493153188194487391358228695151342468224877086896425368422810438268966043143
5922397519756497357499967505758679688646649075302803539077528386858224498222588856280163988716395494
3851743918399601630391772093506274643901267107805198009064692093234224193403702061606850299426651476
9908089454731212877225205687361987022780519210425124250789022062818138048190207921943410932369612123
1264625722768733484440412902313033879037929246974105582008193813127877888969955929338924710176760096
4317826621273936149422080698086653588915837724060010304084595878920010121852066682093621607829876763
92635512259975382189797347146626

[9]> (compile 'fibo) (compile 'fibo*)  ;; switched to compiled code

 
NIL ;
NIL
[10]> (time (fibo 3500))

Real time: 0.0 sec.
Run time: 0.0 sec.
Space: 566808 Bytes
2071302422030262753416199537299341464207691967344600973326088247223853841292493160797697343340451944
4976593116933291600999770493153188194487391358228695151342468224877086896425368422810438268966043143
5922397519756497357499967505758679688646649075302803539077528386858224498222588856280163988716395494
3851743918399601630391772093506274643901267107805198009064692093234224193403702061606850299426651476
9908089454731212877225205687361987022780519210425124250789022062818138048190207921943410932369612123
1264625722768733484440412902313033879037929246974105582008193813127877888969955929338924710176760096
4317826621273936149422080698086653588915837724060010304084595878920010121852066682093621607829876763
92635512259975382189797347146626
[11]>

-------------------------------------------------------------------------------------------

best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 10, 2014, 01:12:12 AM
Rob,

CLisp unwinds recursion to iteration, interpreted or otherwise. Or it may use a cache transparently. Or both. And noone knows what else.

DynLisp is in fact a rudimentary Scheme and it can't optimise recursion to iteration. I haven't seen a generalized algorithm to recognize and perform such an optimization from either you or Charles yet and I don't know where to look for it on the net. At any rate, it is too early for DynLisp to compete with mature LISP compilers but I'm seeing great potential in it to compete with rank-and-file LISP interpreters. And it also is my own one and it is hosted within the same Fbsl.exe that already incorporates three other no-nonsense languages -- BASIC, C, and Asm. :)

Title: Re: Lisp in Basic
Post by: RobbeK on September 10, 2014, 01:35:15 AM
Hi Mike,

You probably used a double recursive mechanism for your benchmark,  from there I was interested to see how single rec. compares to double rec.

in Scheme that's

(define fibo*
   (lambda (a b x)
     (if (= x 0) a
        (fibo* b (+ a b) (- x 1)))))

(define fibo
   (lambda (x)
     (fibo* 1 1 x)))

;; can be speeded up one cycle     by (if (= x 1) b    ;;;

recursion / iteration

http://cs.saddleback.edu/rwatkins/CS2B/Lab%20Exercises/Stacks%20and%20Recursion%20Lab.pdf      (??)

best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 10, 2014, 01:43:00 AM
Thanks for the pdf Rob,

I'll look through it, perhaps it can give me ideas.

I'll post the benchmark results a little later (need to have some rest). I am already able to translate myself such simple pieces of LISP code from one dialect to another. :)

See you in the evening.


P.S. Hehe, FiboRob appeared to be incongruously faster in both implementations. It is in fact so fast that the results are actually app load/unload timings. (Fbsl.exe is a much heavier app and its three engines (actualy three and a half :) ) do take time to initialize)

Can you make every LISP program that fast?  ;)

.
Title: Re: Lisp in Basic
Post by: RobbeK on September 10, 2014, 12:30:19 PM
Hi Mike,

"Can you make every LISP program that fast?  "  -- it worked with the Ackermann too  8)

Well, it works with accumulators , in this case a and b

From a mathematical viewpoint this form has enormous advantages :

- you can restart from any value a and b from the series (i.o. starting over from 1 again)
- it gives possibities analyzing things p.e. returning also the factor between two sequential elements of the series :

(defun fibo*  ( a b x)
    (if (= x 0)  (list a (/ b a))      ;;;;;  extra info returned
        (fibo* b (+ a b) (1- x))))

here the cadr gives the value nth+1 term / nth term :   if x is high enough, you will see it becomes the value of the golden ratio !!!! -- going further, you can completely and exactly make the fibonacci analytic for every real and complex number.

This may be the unspoken disadvantage of Lisp -- every piece of code may reveal your capabilities (or lack of same).  (Lisp is limited to the brain of the hacker/coder  ::)  )

The only thing remaining is to understand the lambda-macro , a lot of coders fail to do so.

If you understand next , you know everything about Lisp there's to know about :

(define not-if
  (lambda-macro (condition a b)
    (if (eval (not condition)) (eval a) (eval b))))

or

(define not-if
  (lambda-macro (condition a b)
    (if (eval condition) (eval b) (eval a) )))

It's easy --  the lambda-macro does not evaluate things , it copies and has to be forced by eval to evaluate its arguments, that's all  -- it is an extremely powerful tool   (it's somewhat more complicated with compilers , but only a little step -- it uses (eval-when    ) and some other tricks

best Rob


Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 11, 2014, 05:55:44 AM
Yes Rob,

I'm seeing the benefits of lambda-macro very clearly. It introduces lazy evaluation of the lambda's intrinsic components and in this way it effectively halves the costs (overhead) of overall evaluation and consequently doubles its speed if the both components are equally computationally heavy.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 11, 2014, 06:20:52 AM
Thanks for the pdf Rob,

I'll look through it, perhaps it can give me ideas.

That's it, Rob!

Quote from: PDF
The following strategy can be used to the remove the recursion from a recursive routine, although not elegantly. There might be a far more pleasing method for a particular routine, but this technique is very instructional. It allows you simulate the system stack by declaring your own stack structure and manage the recursion. It is accomplished as follows:

i) Each time a recursive call is made in the algorithm, push the necessary information onto your stack.
ii) When you complete processing at this deeper level, pop the simulated stack frame and continue processing in the higher level at the point dictated by the return address popped from the stack.
iii) Use an iterative control structure that loops until there are no return addresses left to pop from the stack.

Thanks for sending me to my first school grade again! :D
Title: Re: Lisp in Basic
Post by: RobbeK on September 11, 2014, 12:25:33 PM
Great  :)

An addendum about the lambda-maco's  -- this is NewLisp , infact it uses the ancient (fexpr    )  , it was buried in the 70s when the UNIX systems started to compile Lisp code. 
Strangely the NewLisp is very close to the original McCarthy Lisp of the end 1950s (and in fact so is PicoLisp ).
All these 3 (Mr McCarthy (the inventor) , Mr Lutz Mueller (NewLisp) and Alexander Burger (PicoLisp) are somewhat convinced their languages can not be compiled ).
So the "desecration" of the fexpr "corpus" is very logical -- it works in an interpreter , and maybe OldLisp is a better name for NewLisp  ::)

I think recursion->iteration can be simulated @ Lisp level too --

the definitions of push and pop are easy :

;;  Scheme flavor ;;;


(define push
  (lambda (data stack)
   (set! stack (cons data stack))))

(define pop
  (lambda (stack)
    (let (( result (car stack)))
      (set! stack (cdr stack))
    result )))

with the usual advantage that here the stack is a typeless and variadic container 

best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 11, 2014, 03:53:17 PM
Strangely the NewLisp is very close to the original McCarthy Lisp of the end 1950s
Are you really that ancient, Rob? :o

:D

Quote from: Rob
I think recursion->iteration can be simulated @ Lisp level too --
Did you know that almost all existing LISP-to-C and LISP-to-Asm translators are actually written in LISP? Their source code is thus an order of magnitude shorter than its respective C or assembly analog. :)
Title: Re: Lisp in Basic
Post by: RobbeK on September 12, 2014, 11:11:21 AM
Hi Mike,

"that ancient"  -- I have a copy of the original Lisp, rewritten in ...  Lisp  !!
(I was born the eleventh year after the end of the Great War .. it was dark and snowing , that's all I remember  8)

"Did you know that almost all ..  " Never been looking under the hood of a Lisp-system .. but I had a book describing how to build a Lisp compiler , ...  in the end the compiler compiles itself ..

As for Common Lisp (and very similar Scheme) the macro's work as this

::  CL flavor ;;

(defvar a 2)
(defvar b 3)
(defvar operator '+)
(defvar L '(1 2 3))

the mechanisms are the backquote (quasiquote)  `  and the ,   (comma)

the backquote starts the copy , the comma forces the evaluation.

`( * ,a ,b)  copies to (* 2 3)   
`( , operator ,a ,b) copies to (+ 2 3)  , so : (eval `( , operator ,a ,b)) gives 5

it also has the "splicer"  ,@  (removes the parentheses)

`( ,op ,@L) copies to  (+ 1 2 3)   so (eval `( ,op ,@L)) -> 6

the expansion is defined by : p.e.

(defmacro f (operator a b)
  `( ,operator ,a ,b))

(f * 5 6)  -> 30

...  or something as :

(defmacro infix (a operator b)
 `( ,operator ,a ,b))

(infix 6 + 7) -> 13

NewLisp expands its macro's during run-time /  CL during read-time   (the latest NewLisp now also has (macro   ) doing the expanding as well during the program initiation.

best Rob
Title: Re: Lisp in Basic
Post by: JRS on September 12, 2014, 11:46:18 AM
Quote
I was born the eleventh year after the end of the Great War .. it was dark and snowing , that's all I remember

My memory of that time was moving from Cleveland OH (across from the steel mills) to the country where my Dad bought a farm. Mom almost burnt down the house when she was burning cardboard boxed in the fireplace and forgot to open the vent.  ::) Love you Mom! (Mom and Dad are gone now - passed last year)  :'(
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 12, 2014, 11:01:23 PM
1945 plus 11 is 1956 which makes us coevals. :)

I was born on the isle of Sakhalin (that's on the Pacific coast of Russia near the Japanese islands) where my Dad, an army officer, served after the war. The maternity hospital was a two storey building but there's so much snow in March on Sakhalin that my Dad had to lie down on his stomach in the snow to peep through the top of the window into the room on the upper floor where my Mom was holding me high up in her hands showing me to him. And when it was time to take us home from the hospital, we rode on the armor of a battle tank because no other vehicle could break its way through the snow. :) My parents passed away 35 years ago in a car crash but I keep seeing them in my dreams, and now more and more often than before.

Yes Rob, I've looked through the LISP macro basics in the r6rs sources. They look almost as powerful as a full-blown C preprocessor and I'm sure they've been brought to perfection over the countless decades that this language exists. Frankly, I'm becoming more and more possessed by LISP and I would gladly include its clone in the FBSL armory if only I manage to design a reliable JIT compiler for it. But this will take time.
Title: Re: Lisp in Basic
Post by: RobbeK on September 13, 2014, 06:08:00 AM
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"  8)  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 8))"))
     (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 !!           
       



     
 

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 13, 2014, 12:40:35 PM
Hi Rob,


In my case it's March 3, kid! :D


No, Sakhalin is a separate region. Japanese Hokkaido is immediately to the south of it as seen in this map:

(http://geo.web.ru/druza/Image-Map/Sakhalin.GIF)


Hehe, your demo seems clever! And thanks for the clip too. It goes very well with the recent videos posted on the thinBasic forum. :)
Title: Re: Lisp in Basic
Post by: RobbeK on September 14, 2014, 01:21:22 AM
Hi John, Mike,

"nclude its clone in the FBSL armory if only I manage to design a reliable JIT compiler for it."

both CLisp and Racket Scheme , use GNU Lightning JIT :

http://www.gnu.org/software/lightning/manual/lightning.html

from : https://wiki.aalto.fi/download/attachments/40010375/intro-report.pdf
"First JIT compilation system according to Aycock [4] were McCarthy's Lisp
systems in the 1960s. "

best Rob

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 14, 2014, 02:32:29 AM
Hi John,

Is that a farewell from China? :)
Title: Re: Lisp in Basic
Post by: RobbeK on September 14, 2014, 02:56:30 AM
Addendum --

"SyntAna" does fractions and real numbers now -- compiled with the Austin-Kyoto CL...

(took me 20' to find out "" is not a valuable string and GCL doesn't do "appendtext" on textareas .... :(

best Rob
(Japi is a static lib here, will be hard to update it , ???? )

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 14, 2014, 03:07:12 AM
Hi Rob,

No no, no GNU for me, please. That's first and foremost. Secondly, I can cope with machine code generation myself -- FBSL already has two very compact JIT compilers incorporated in its binary, one for Intel assembly, and the other one, for ANSI C. What I actually need is a system that would do LISP (Scheme) syntax translation to either asm or C so that one of my existing machine code generators could do the rest of the work. And that system must be written in C (or assembly) to be compilable with the rest of FBSL sources into the same binary, and it shouldn't add more than 45 or 50KB to its size when compiled.

There are no such systems on the net worth speaking of. Gambit-C and the like are huge and generate terrifically inefficient C code (been there, done that), others that are outputting assembly code are hopelessly incomplete even by r4rs standards.

There is only one project on the entire net that does what I need, and it is Abdulaziz Ghuloum's An Incremental Approach to Compiler Construction. This is a LISP-to-assembly translator that covers the entire r5rs Scheme in its Petite flavor. And it goes under a MIT license too which suits my intentions perfectly.

Regretfully, the compiler itself is written in Scheme and I'm facing a tremendous problem with its portability to C or assembly for compilation into the FBSL binary. The compiler (in fact, translator) is not self-translating. I.e. it runs perfectly from within Petite to translate other scripts' code to asm but it can't translate its own Petite Scheme body to assembly because of a few syntactic constructs that are specific to Petite and do not belong to r5rs proper.

Can I ask you to help me out with this problem? I have about two dozens very similar macros from the compiler code and a couple of their corresponding syntactic prototypes. I need to exclude the prototypes from the code altogether and have the macros unrolled to their pure explicit r5rs compatible form by hand. Perhaps this will make the compiler self-compilable, and then I will be able to include its code regenerated by itself into assembly, in my FBSL compilation.
Title: Re: Lisp in Basic
Post by: JRS on September 14, 2014, 07:45:46 AM
Quote
Is that a farewell from China?

Actually it was from an article about fashion statements in NY.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 14, 2014, 08:49:12 AM
Quote
Is that a farewell from China?
Actually it was from an article about fashion statements in NY.

Oh, so it was a farewell from China Town. :)
Title: Re: Lisp in Basic
Post by: JRS on September 14, 2014, 08:59:56 AM
You missed the humor of the original post. Faking happy when things aren't going as planned.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 14, 2014, 09:17:16 AM
Thanks for making me aware.

Faking happy when things aren't going as planned...

... in NYC? (that's a joke)
Title: Re: Lisp in Basic
Post by: JRS on September 14, 2014, 10:59:30 AM
Quote
... in NYC? (that's a joke)

That was the funnest part.  ;D
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 14, 2014, 01:40:13 PM
OK Rob,

I can narrow down the problem to just the following two cases. Given syntactic Rules I and II and given that I know and understand what such names and procedure calls as e.g. emit-expr, putprop, etc. actually mean, can you please:

i) unroll for me the respective macros 1 to 3 and 1 to 4 to how Scheme would actually see their true code on program load; and

ii) explain to me what the difference is between the arguments of macros 3 and 4 under syntactic Rule II? (why is arg b parenthesized in macro 4?)


Rule I

(define-syntax define-primitive
  (syntax-rules ()
    [(_ (prim-name si env arg* ...) b b* ...)
     (begin
       (putprop 'prim-name '*is-prim* #t)
       (putprop 'prim-name '*arg-count*
         (length '(arg* ...)))
       (putprop 'prim-name '*emitter*
         (lambda (si env arg* ...) b b* ...)))]
    [(_ (prim-name si env arg* ... . vararg) b b* ...)
     (begin
       (putprop 'prim-name '*is-prim* #t)
       (putprop 'prim-name '*arg-count*
         (length '(arg* ...)))
       (putprop 'prim-name '*vararg* #t)
       (putprop 'prim-name '*emitter*
         (lambda (si env arg* ... . vararg) b b* ...)))]))

1.
(define-primitive (fxadd1 si env arg)
  (emit-expr si env arg)
  (emit "  add $~s, %eax" (immediate-rep 1)))

2.
(define-primitive (fx+ si env arg1 arg2)
  (emit-binop si env arg1 arg2)
  (emit "  add ~s(%esp), %eax" si))

3.
(define-primitive (foreign-call si env name . args)
  (let ([new-si (let loop ([si (+ si wordsize)]
            [args (reverse args)])
                  (cond
                   [(null? args) si]
                   [else
                    (emit-expr-save (next-stack-index si) env (car args))
                    (loop (next-stack-index si) (cdr args))]))])
    (emit-adjust-base new-si)
    (emit-call name)
    (emit-adjust-base (- new-si))))


Rule II

(define lib-primitives '())
(define-syntax define-lib-primitive
  (syntax-rules ()
    [(_ (prim-name arg* ...) b b* ...)
     (begin
       (set! lib-primitives (cons 'prim-name lib-primitives))
       (putprop 'prim-name '*is-lib-prim* #t)
       (putprop 'prim-name '*arg-count*
         (length '(arg* ...)))
       (putprop 'prim-name '*lib-code*
         (make-lambda '(arg* ...) (make-begin '(b b* ...)))))]
    [(_ (prim-name . varargs) b b* ...)
     (begin
       (set! lib-primitives (cons 'prim-name lib-primitives))
       (putprop 'prim-name '*is-lib-prim* #t)
       (putprop 'prim-name '*arg-count* 0)
       (putprop 'prim-name '*vararg* #t)
       (putprop 'prim-name '*lib-code*
         (make-lambda 'varargs (make-begin '(b b* ...)))))]
    [(_ prim-name b)
     (begin
       (set! lib-primitives (cons 'prim-name lib-primitives))
       (putprop 'prim-name '*is-lib-prim* #t)
       (putprop 'prim-name '*lib-code* 'b))]))

1.
(define-lib-primitive (length lst)
  (if (null? lst)
      0
      (fxadd1 (length (cdr lst)))))

2.
(define-lib-primitive (vector . args)
  (let ([v (make-vector (length args))])
    (fill args (lambda (index arg) (vector-set! v index arg)))
    v))

3.
(define-lib-primitive stdout
  (make-output-port "" 1))

4.
(define-lib-primitive (current-output-port)
  stdout)
Title: Re: Lisp in Basic
Post by: RobbeK 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
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky 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. :)
Title: Re: Lisp in Basic
Post by: RobbeK 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

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky 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.

.
Title: Re: Lisp in Basic
Post by: RobbeK 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
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 16, 2014, 05:28:13 AM
Hi Rob,

Download and install MS HTML Help Workshop (http://www.microsoft.com/en-us/download/details.aspx?id=21138) -- 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! :)
Title: Re: Lisp in Basic
Post by: RobbeK 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

 ;)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky 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. :)
Title: Re: Lisp in Basic
Post by: RobbeK 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
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky 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.... ;)

.
Title: Re: Lisp in Basic
Post by: JRS 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?

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky 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... :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky 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

.
Title: Re: Lisp in Basic
Post by: Charles Pegge 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.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky 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)
Title: Re: Lisp in Basic
Post by: RobbeK on September 18, 2014, 01:28:06 PM
Mike,

Does this work in your Lisp(s)  ??

(define (tst x)
  (let ((f (lambda (x i acc)
            (if (zero? i) acc
                (f x (- i 1) (+ acc x))))))
  (f x x 0)))

or


(define tst (lambda (x)
  (let ((f (lambda (x i acc)
            (if (zero? i) acc
                (f x (- i 1) (+ acc x))))))
  (f x x 0))))

stupid method to calculate the square of a number -- but Racket Scheme refuses it (this is NewLISP, -- but code should be the same ...  if the local function is not recursive it does work in Racket Scheme ..   strange  ???

Infact CL uses another method when the local is recursive (normally it is (flet ... ) , but then (labels   ) has to be used :

code in CL

(defun tst (x)
  (labels (( f ( x i acc)
         (if (zerop i) acc
             (f x (- i 1) (+ acc x)))))
    (f x x 0)))


best, Rob

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 18, 2014, 01:51:13 PM
Hi Rob,

How do you test such a function and what is its expected visible output, please?

(tinyscheme.exe yields unbound variable f if I try to call, say, (tst 5))

(same in Petite Chez)

(same in Gambit)
Title: Re: Lisp in Basic
Post by: RobbeK on September 18, 2014, 02:02:27 PM
Hi Mike,

Yes something as (test 5)  -- Racket Scheme gives the "unbound variable error" too ...
(but if the local function is non-recursive it it is bound ...    ::) ::)

..  and your brainchild, what does it ??


best Rob
 
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 18, 2014, 02:16:17 PM
If that (let ((f ... stands for (let f (( ... then my brainchildren won't be able to cope with it at all yet because they don't currently support named let. Actually OxyLISP returns 0 not being able to intercept the unbound f. And this isn't its only deviation from a canonical Scheme.
Title: Re: Lisp in Basic
Post by: RobbeK on September 18, 2014, 02:30:31 PM
Hi Mike,

just ( let (( variable ...  )      , adding a lambda-list to a local variable,   (NL doesn't have named let's) 
But this may explain something about CL uses two different mechanisms for local functions (flet ) and (labels ) -- NewLISP doesn't care , it does both ...
(but I'm not a Scheme specialist of course)

best Rob
Title: Re: Lisp in Basic
Post by: JRS on September 18, 2014, 02:47:21 PM
Quote from: Rob
(but I'm not a Scheme specialist of course)

Lets hope that changes soon!  :-*
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 18, 2014, 03:10:21 PM
Hello Rob,

The problem with your code is that within your lambda, you're trying to access an f which isn't bound in its environment because it isn't enumerated in lambda's list of formal parameters. The f in let and the f within lambda are two different fs, and it is the f in lambda that is flagged as unbound, which is only natural IMHO.

In some dialects, you may try to define local vars but this clearly isn't what you want to do, n'est-ce pas? So just forget. This is a dead end, and any dialect that would actually let you do it is not Scheme.

See how I've grown up to criticise your LISP code, Rob? :D
Title: Re: Lisp in Basic
Post by: RobbeK on September 18, 2014, 03:18:13 PM
Yep, great Mike ...

Got it now , after reading the Common Lisp specifications -- the trick CL uses    :

labels

labels is equivalent to flet except that the scope of the defined function names for labels encompasses the function definitions themselves as well as the body.

(flet  ) defines a local function -- but it can not be of the resursive kind (by reasons you mentioned)

 ;)  Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 18, 2014, 05:19:54 PM
Rob,

Is this what in fact you're trying to do (squeeze two defines into one?):   ;)

Code: [Select]
TinyScheme 1.41
ts> (define f (lambda (x i acc)
(if (zero? i) acc (f x (- i 1) (+ acc x)))))
f
ts> (define (tst x) (f x x 0))
tst
ts> (tst 5)
25    ; <===== IS THIS IT?
ts>

Hehe, I really don't know if it's possible in Scheme at all. But then I'm no guru either... But the only way to achieve it in OxyLISP is currently as shown in the snapshot below.

.
Title: Re: Lisp in Basic
Post by: RobbeK on September 18, 2014, 11:27:50 PM
Hi Mike,

Yep,  I was looking for the Scheme way of (flet ) and (labels )  from CL

this works of course :

(define test (lambda  (x)
  (let ((f (lambda (i) (* i i))))
    (f x))))

but f must be non-recursive ...

(i think it has to do with the difference between lexical and dynamical scope -- (?) ...  everything NewLisp does, is somewhat similar with the older Lisps , it uses a lot of things from the 60/70s, like the fexpressions etc ...   in fact the (first ) and (rest ) for (car ) and (cdr ) is the way McCarthy wrote his first documents/papers .. only later when ported to an IBM machine it was replaced by the then usual car / cdr IBM code ... )  NewLISP accepts recursive local functions ....

best Rob
Title: Re: Lisp in Basic
Post by: RobbeK on September 19, 2014, 12:39:36 AM
Hi John,

they say : practice makes perfect  :) , we'll see -- the "hygienic" macro system is completely different from CL though ...


best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 19, 2014, 01:04:53 AM
Hi Rob,

(define test (lambda  (x)
  (let ((f (lambda (i) (* i i))))
    (f x))))

but f must be non-recursive ...

Where did you find recursion here? :o

It's true that the f call is in the tail position as per definition but the call itself is made physically only once and yields the answer without going any deeper into itself...

Or am I missing something?

.
Title: Re: Lisp in Basic
Post by: RobbeK on September 19, 2014, 01:13:18 AM
Hi Mike,

The first try contained a recursive local function , I'm just showing what does work with (let   ).
However the problem is solved now , Scheme has (letrec   )  , it even allows to use not yet declared functions (but later defined within the (letrec ) scope :

this works :

(define tst (lambda (x)
              (letrec (( f (lambda (i x acc)
                           (if (zero? i) acc
                               (f (- i 1) x (+ x acc))))))
                (f x x 0))))


this doesnt  (my first try, using a recursive lambda list within a (let   ((   .. )))

(define tst (lambda (x)
  (let ((f (lambda (x i acc)
            (if (zero? i) acc
                (f x (- i 1) (+ acc x))))))
  (f x x 0))))

so, problem solved  ;)

best, Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 19, 2014, 01:19:02 AM
Yes, letrec works here but there's no letrec in OxyLISP. :)
Title: Re: Lisp in Basic
Post by: RobbeK on September 19, 2014, 02:24:25 AM
Hi Mike,

then you will have to use global defined lambda lists .... 
the intention is to make compact , ultra-fast recursive constructions ---   have a look :  (thanks to (letrec ... )

#lang racket


(define (fibo x)
  (letrec (( f (lambda (a b x)
                 (if (zero? x) a
                     (f b (+ a b) (- x 1))))))
    (f 1 1 x)))

-----------------------------------------------------------REPL

> (time (fibo 3000))
cpu time: 0 real time: 0 gc time: 0
6643904603669600722802178478660283842441635124527832594055797655426212141612192573964498109829998203
9113222680280946513244634933199440943492601904534272374918853031699467847355132063510109961938297318
1622585687336939784373527897555489486841726131733814340129175622450421605101025897173235990662770203
7564387865175305471011237488491402526861201040326470251455989566759021350105669097831249594364698255
5831428970135422715178460286571078062467510705656982282054284666032181383889627581975328137149180900
4412219124856375121694811728724213667814577326618521478357661859018967313354840178403197559969056510
791709859144173304364898001
>

best, Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 19, 2014, 03:56:37 AM
Rob,

I do not believe these zero timings belong to true recursion. As long as your code
(f b (+ a b) (- x 1))
is defined properly tail recursive, any contemporary LISP will optimize it transparently to iteration in both interpretative and precompiled environments.

Don't get mislead by the timings. What you see doesn't pertain to recursion. It pertains to the clever implementation of the language that guarantees that each and every occurence of proper tail recursion irrespective of its complexity will be unrolled into equivalent iteration automatically. All you're supposed to do is just emit properly tail recursive code. :D


Oh, and by the way: (the result tends to #INF at larger args due to 64 bit double restrictions)

.
Title: Re: Lisp in Basic
Post by: RobbeK on September 19, 2014, 04:29:49 AM
Hi Mike,

Sure, i'm fully aware of the fact Racket Scheme does TCO , but it's the way of writing things ...  in the iterative way, I have to declare both accumulators a & b : resulting in something as (NL style)

(define fibo (lambda (n)
   (let ((a 1) (b 1) (res 0) )                      ;; temporarily res ;;  psetq  (parallel setq in CL sometimes does weird things)
     (dotimes (i n)
         (setq res (+ a b) a b b res))           ;; NL short for ( set! res (+ a b)) (set! a b) (set! b res)  -- needs 3 lines in CL / Scheme
      a )))

You're of course 100% correct , both codes (it & recur) give the same benchmark

It is not so that TCO is completely solved in all CL's -- 

CLisp p.e. uses the GNU Lightning JPTAIL (the difference between self-calls and general TCO)  ---   safe are Clozure CL and Steel Bank CL  (from those I worked with ).
(this is a nice document : http://0branch.com/notes/tco-cl.html )  -- with disassembled code ....

So, my only reason is that a mathematical formula is written shorten in a recursive way ( this doesn't mean I like recursive program flow --  unless binary trees are set up ---      but here NewLisp even has (dotree       )  it is very poor on recursion and doesn't do any optimizing at all ..  and also giving the fact I do not like a helper function is floating around the code somewhere , I like them inside the definition which is possible with Scheme's (letrec ) , CL's (labels ) and NL's (let   )

(the true speed comes from using accumulators , which take all numeric data except the loop index )

best Rob   

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 19, 2014, 04:48:25 AM
Hehe moreover, rumor has it there are some LISP gurus (such that are making competitor companies tremble, as you told us once) who are able to write properly tail recursive functions with additional recursive calls placed in such a clever way within the function body that, upon the initial optimization of proper tail recursion occurences, these additional recursions are also promoted to proper tail positions within the unrolled iterations where they can be TCO-ed by the compiler again. :D
Title: Re: Lisp in Basic
Post by: RobbeK on September 19, 2014, 12:10:48 PM
héhé ,   8)

but , be very careful with Lispers -- they do their very best to get bigger fees with less labour ( like that guy writing the macro's in that piece of literature )..

best, Rob


.
Title: Re: Lisp in Basic = VICTORY! :D
Post by: Mike Lobanovsky on September 20, 2014, 01:47:16 PM
Dear friends,

I hasten to inform you that I've been able to fix the OxyLISP garbage collector and now the program works as expected barring a couple minor glitches that I hope to fix shortly.

I think we should all thank Charles for his wonderful work on OxygenBasic. I understand that it's still a W.I.P. in many respects but its capabilities even as they are now have already promoted it to the first ranks of indie BASIC compilers available on the contemporary market.

My toughest test (Rob's ASCII Mandelbrot script) shows that OxyLISP does its interpretative job about four times faster than tinyscheme. You can see the comparative results in the accompanying snapshot with your own eyes. Just FYI, tinyscheme's own typical startup/shutdown time is around 32 milliseconds therefore it hardly affects the overall results as seen in the snapshot.

Bravo Charles! :D

.
Title: Re: Lisp in Basic
Post by: RobbeK on September 21, 2014, 03:03:43 AM
Great !!!

Been thinking about your previous post --    there may be very clever ways in Lisp to handle mutual , nested or whatever recursion.  After all Lisp is famous for trampolining , which in fact means that there is a kind of "mother function" which in an iterative way outputs not values but functions -- wrote something ,   the functions generated are not evaluated till a certain condition is reached ,   it are just patterns , here an index has been used , but of course a more general   (while    ) can be used too ,   or a   (catch      (throw  ) construction or whatever ........

;;------------------------------------------------------------------------------

>
(define fac
(lambda (x)
 (let ((pattern (list x '*))
         (print-it-nice (lambda (m)
               (let ((fi (cons 'fac (first m))))
                 (reverse (cons fi (rest m)))))))
    (dotimes (i (- x 1))
   (push (- (first pattern) 1) pattern)
   (println (print-it-nice pattern)))
   (eval (reverse (rest pattern))))))


> (fac 10)
(* 10 (fac 9))
(* 10 9 (fac 8))
(* 10 9 8 (fac 7))
(* 10 9 8 7 (fac 6))
(* 10 9 8 7 6 (fac 5))
(* 10 9 8 7 6 5 (fac 4))
(* 10 9 8 7 6 5 4 (fac 3))
(* 10 9 8 7 6 5 4 3 (fac 2))
(* 10 9 8 7 6 5 4 3 2 (fac 1))
3628800

 8)

Important : only the last list is evaluated , nothing is calculated in-between (in fact , it can't be computed ) !!!! , nothing is stacked somewhere   -- in memory only the length of the list you see is needed.....

(infact I'm using a dirty trick -- the lists I use are reversed during computing, with the operator coming at the tail -- avoiding evaluating    ;) 

best Rob

(only an example of a function generating functions -- for x!   the more compact way is :

(define fac (lambda  (x)  (apply * (sequence 1 x))))

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 21, 2014, 05:05:35 AM
Hi Rob,

Thanks for the example. I understand your theory behind your code (LISP code being ordinary datum if quoted, similar to data in its proper sense) and I can read and understand almost all of it except for (push). What does it actually do?

Now Rob, I need your help.

I)

1. Can Scheme's (do) as per its syntax rules defined in the .CHM that I posted earlier be written as a user-defined function using Lisp-in-Basic's vocabulary as per the .PDF that you also have?

2. Can Scheme's named (let) as defined per the .CHM be written in Lisp-in-Basic's vocabulary?

3. Can Scheme's (letrec) as defined per the .CHM be written in Lisp-in-Basic's vocabulary?

Please note that Lisp-in-Basic permits explicit (define)s local to a procedure and visible only within its own environment.

I need them very very badly. (and I'm currently interested only in OxyLISP (= Lisp-in-Basic) compatible code)


[UPD] Rob, I've been able to do it myself following the directions for the derived expressions' semantics that I found in the R4RS standard. :)


II)

Are there any standard keywords or macros in any of the LISPs known to you that would allow the programmer to selectively suppress REPL's output to the console in some arbitrary parts of their code? Something of the (mute)/(unmute) kind?


Thanks!


P.S. Your (define fac (lambda  (x)  (apply * (sequence 1 x)))) is inoperative in any Scheme that I have including OxyLISP, even if deprecated (sequence) is changed to modern (begin). It yields unacceptable arguments for the (*) procedure.

P.P.S. The 2nd argument to (apply) must be a list, not a sequence. :P
Title: Re: Lisp in Basic
Post by: JRS on September 21, 2014, 10:15:22 AM
Quote from: Mike
I need them very very badly. (and I'm currently interested only in OxyLISP (= Lisp-in-Basic) compatible code)

Please define what Lisp-in-Basic compatible code means. Does Arthur's implementation meet any of the Scheme standards or is it a hybrid?  Do you have any documentation (other than the original provided by Arthur) that we can use with OxyLISP when you release it?
Title: Re: Lisp in Basic
Post by: RobbeK on September 21, 2014, 11:22:03 AM
Hi John, Mike

-- the sequence is NewLISP nomenclature (oops, sorry) - in Racket Scheme it is (range from to) or the same as a stream (in-range from to)  -- it does not exist in CL either --  here's "a" definition :

(define seq (lambda (from to)
              (letrec (( seq* (lambda (from to L)
                             (if (> from to) (reverse L)
                                 (seq* (+ from 1) to (cons from L))))))
                (seq* from to '()))))

------------------------------ repl

Language: racket; memory limit: 512 MB.
> (seq 1 22)
'(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22)
>

--------------------------------

(push  ) is the destructive form of (cons  )  -- (cons ) is constructive , it does not change any of the arguments

(define a (list 1 2))
(push 6 a)
a -> (6 1 2)

however, when at first sight , this looks extremely childish to put it into a definition, it isn't -- it surely isn't ...

(define (push item L)
  (set! L (cons item L)))    does ******NOT******** work  (in any LISP dialect)

the reason is that if L is a list it is represented by the list and not by its location (pointer)
infact this definition does it all correct, but it is constructing a list that is lost and does not reach the location L is pointing at.

the correct definition is : (and it needs a macro)

NewLISP

(define-macro (push it L)
  (setq (eval L) (cons (eval it)  (eval L) )))

& Common Lisp

(defmacro push (x L)
   `(setq ,L (cons ,x ,L)))

(I'll study the Scheme macro's soon -- I will be able to define (push ) and (pop ) then )

----------

(mute) (unmute) 

I only know (silent                   ) in NewLISP ,,   it's a problem too for me in LispIDE    (the Unix/Linux users , most of the time are in EMACS -- which is run in ELisp (so it runs two Lisps at the time -- one is named "inferior Lisp" -- and it should be easy to tell the one Lisp not to emit the output from the other ...   some time ago , there was someone here who worked with Emacs (he introduced himself as something as   "  a not so good programmer " -- he will know (and he's probably a lot better than he thinks)
 

best Rob,
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 21, 2014, 11:26:10 AM
First of all "Hi John",

We haven't yet met with you today. :)

Lisp-in-Basic is an incomplete and inconsistent subset of R4RS. I'm struggling to desperately push it through to some resemblance with R5RS that's already outdated but still usable (see e.g. tinyscheme). Modern R6RS is totally out of reach.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 21, 2014, 11:32:47 AM
Rob,

If you have (silent) then how can you (unsilent) anything? Or does (silent) mute only the output that is within its scope, e.g. (silent (display "bla bla")) not displaying anything at all?

Quote from: Rob
> (seq 1 22)
Aha! So it constructs a list with values in the range of 1 to 22!
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 21, 2014, 11:39:08 AM
John,

When OxyLISP is out, it will have its own .PDF mostly based on Arthur's description but with new features added. OxyLISP deserves it. :)
Title: Re: Lisp in Basic
Post by: JRS on September 21, 2014, 11:55:16 AM
That's great Mike. A tribute to both Arthur and Charles.

I'm glad my little QB to SB experiment resulted into something worthwhile. You did a great job of managing that project!
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 21, 2014, 12:21:54 PM
Thanks John,

But the work isn't complete yet and so far OxyLISP exists solely on my computer. It will become "a project" when it goes public. :)
Title: Re: Lisp in Basic
Post by: JRS on September 21, 2014, 12:28:01 PM
Sounds great!

(https://pbs.twimg.com/media/Bvp0ylICEAAKsm0.png:large)
Where Mike's code really comes from.  :-*
Title: Re: Lisp in Basic
Post by: RobbeK on September 21, 2014, 12:40:06 PM
Hi Mike,

There's no (unsilence)  .. the silence ends at the first hit of "Enter" key ..    (display )  etc ... act as normal.

Aha! So it constructs a list with values in the range of 1 to 22!

yep, and with the previous "pattern matching" algorithm I wrote , it is possible (very easy) to define : (...   L limit) -> S

(...  '(1 2 3) 20) generating (1 2 3 4 ...  20)
(...  '(2 4 6) 20) generating (2 4 6 8 ...  20)
(...  '(1 4 9) 20) generating (1 4 9 16)

etc...
Reinventing the wheel -- it's standard built in Haskell   :-[

best Rob   
 
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 21, 2014, 01:42:23 PM
Rob,

Would you disagree if I add (mute <expression1> . . .) to OxyLISP's vocabulary? Not as a macro but as a basic keyword? (errors would be displayed as usual)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 21, 2014, 04:07:37 PM
Charles,

How would you describe, "compliment"-wise, what Oxygen's NOT is doing with a fractional floating point number?
Title: Re: Lisp in Basic
Post by: Charles Pegge on September 21, 2014, 04:52:59 PM
Mike,

NOT will negate the number then subtract 1.

This is logically correct when converted to an integer, but is not the actual compliment of the binary representation of a float.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 21, 2014, 05:17:16 PM
Thanks, Charles.
Title: Re: Lisp in Basic
Post by: RobbeK on September 21, 2014, 11:05:03 PM
Hi Mike,

Would be great , possibly

(mute

  (define ..........; )
  (define ......  )
 .
 .
 ;;  etc 

)

working with blocks could be a more general construction ??

Another speedy prog , I'm thinking about a more universal solution.  This one finds all 3² magic squares (written in NewLISP)

best, Rob




.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 22, 2014, 11:38:51 PM
Thanks Rob! :)

OxyLISP doesn't support macros or syntax rules but only (define)'s.

In order to bypass this restriction to some extent and be able to create (for now hardcode only!) new "encompassing" syntactic forms which weren't available in Arthur's original Lisp-in-Basic, such as

(mute <expression1> . . . )

(when <test> <expression1> . . . )

(unless <test> <expression1> . . . )

(do ((<variable1> <init1> <step1>)  . . . )
    (<test> <expression> . . . )
    <command> . . . )


and others that can't be expressed in terms of simple (define)'s and (lambda)'s, I had to re-write practically all GOTO's in the sources to GOSUB/RET's. That would be equivalent to full blown SUB/END SUB's without arguments, and it would make interpreted SBLisp and FBLisp run yet at least 1.5 times slower than before, slow as they are now.

But OxyLISP's assembly call/ret's (equivalent to GOSUB/RET's) that replaced jmp's (former GOTO's) are indeed so fast that I'm not seeing any detectable speed deterioration due to such changes. This makes me very enthusiastic about the expandability of OxyLISP's vocabulary even though it can be achieved only by hardcoding rather than macros when defines and lambdas are insufficient.


P.S. Are (first) and (rest) simple aliases to (car) and (cdr)?
Title: Re: Lisp in Basic
Post by: RobbeK on September 23, 2014, 07:48:16 AM
Good news  (again) !

Macro definitions are extremely powerful in Lisp -- a macro definition of (define ...  )

(defmacro define (name params &rest body)
‘(progn
       (setf (symbol-function ’,name)
       #’(lambda ,params
               (block ,name ,@body)))
        ’,name))

-----------------------
but, I decided -- the combination of NewLISP and Oxygen , or a modern Scheme as BigLoo seem more suitable to me than the Common Lisps around.   (and I'll keep the "brutal" STALIN optimizer too). 
yep, a combination like NewLISP and Oxygen is fine : Lisp for the abstractions, and O² for speed   -- the FFI of NewLISP is great and NL does big ints ,  the macro's are somewhat easier to write than in CL ...  ok , decided  8)

yes, (first ) and (rest ) are the same as (car ) and (cdr ) ,  it are the original names
as can be seen on this document from McCarthy end 1950s

http://farm9.staticflickr.com/8232/8435395097_3b717701ec_z.jpg


best, Rob
Title: Re: Lisp in Basic
Post by: JRS on September 23, 2014, 08:01:49 AM
Hi Rob,

OT - Did you ever give CERN ROOT for Windows a try? It seems a lot of the work you put into presentation is simplified with ROOT. The interpretive C and high level graphics API seems appealing. Compiling your projects to C is also cool. I'm not a MATH pro so ROOT is overkill for my needs.

Title: Re: Lisp in Basic
Post by: RobbeK on September 23, 2014, 12:30:27 PM
Hi John,

Never tried it  :-\

But did play with DISLIN a few times :
from :  http://www.mps.mpg.de/en

(specific : http://www.mps.mpg.de/dislin/ )
-- there are/were? bindings for FreeBasic (Win/Linux) ---

no, what I do not like about CL this moment, is that I'm just collecting dependencies instead of effective code --- it's near the  Babel's confusion of tongues  (despite Quicklisp and other things )

best Rob

p.s.   does this work on an alien computer (attached)
I'm not sure where NewLISP expects the dll
(it's a nicer presentation of the magic 3x3 squares (sum of the rows and columns has to be the same using the number 1 ... 3²)  -- finding the solutions out of the combinations of the 9 numbers takes no time at all
(presentation is done including delay loops -- NL is really fast for an interpreter )



 

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 23, 2014, 01:35:03 PM
This one looks nice!

A Windows DLL will always work if it is stored beside its parent EXE. No need to ponder over where else to install it to.
Title: Re: Lisp in Basic
Post by: JRS on September 24, 2014, 01:09:25 AM
Quote
But did play with DISLIN a few times

Be forewarned that if you try to use DISLIN=/usr as your install path, you will trash your Linux install.  :'(

Rebuilding my Linux system isn't going to be fun. Luckily I didn't lose anything and have a spare Linux laptop to get me through it.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 24, 2014, 12:07:44 PM
Hi John,

Could I ask you to send an e-mail to Mr Arthur Nunes-Harwitt and ask him, on my behalf, for his kind permission to for me to decompose his LISP-in-BASIC .PDF file and add my minute corrections and description of the new language features? I'm currently working to add R5RS style Scheme macro system to the language, quasiquotes and stuff included.

Thanks!
Title: Re: Lisp in Basic
Post by: JRS on September 25, 2014, 01:45:04 AM
Hi Rob,

Just getting back online with my development laptop after the Dislin disaster. (Rebuild of my Linux system)

A silver lining was I upgraded to 14.04.1 LTS and cleaned a lot a crap off my disk that now resides on my 5TB USB drive.

With this version of Ubuntu it comes with LibreOffice Math. (see attached) You should give it a try and see if it blows up your box.  :)

.
Title: Re: Lisp in Basic
Post by: RobbeK on September 25, 2014, 12:54:04 PM
Hi John,

Sorry to hear DISLIN torpedoing your Linux distro --  (I used it with FB under Windows -- only  for a short while ).

..  but, my heart is low for the moment , decided to work with NewLISP for future projects , and reading some comments and critiques , i found next :

--------------------

I’ve been working in Lisp for 30 years now and after reading the manual for newLISP my feelings are that Lutz Mueller never understood what it is in Lisp that makes it still the most powerful programming language around. What he created is far far closer to scheme than to a modern Lisp. I wish he had called it newSCHEME so that people don’t get a bad impression of Lisp from newLISP.

---------------------

After 30 years -- doesn't  (s)he know Scheme is a daughter of "Mother Lisp" --
Scheme is even older than Common Lisp --- 

...  what a nonsense ........   I mean, especially after 30! years ...  (sometimes i do not like the "world wide web" at all)

best Rob

LibreOffice Math  :)   , nice , I'll use it

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 25, 2014, 03:34:11 PM
Hi Rob,

In Russian, LISP is masculine while Scheme is feminine and perhaps that's why I've chosen the latter (quite subconsciously, hehe) for my exercises. And don't get so upset about that marginal message; there are so many people around who really don't know what they're either saying or doing regardless of being in business for only 3 or already 30 years.


Now guys I need your advice. After so many efforts put into LISP-in-BASIC and when its O2 exe size is well on the wrong side of 100KB but still lacking a lot of essential features, I came across a Scheme implementation I called nanoscheme that does much, much more than the current OxyLISP, is 3 times faster than tinyscheme (see the attached benchmark of doubly recursive fibo(35)), has a 5 times smaller executable than OxyLISP to say nothing of tinyscheme, has a clearly defined source code structure, is easy to port to BASIC, and is easily expandable to a full numeric tower and nearly all of R5RS standard even though it doesn't fully support R4RS in its present state.

I want to give up LISP-in-BASIC right away as I see no more reason to maintain it; it's a complete mess as compared to nanoscheme. It simply doesn't deserve any more of our time. It's been a nice toy to get in line with the ABC's of LISP but it's becoming more of a burden than a pleasure to work with.

Would you mind waiting for another week till I get nanoscheme up and running in OxygenBasic?

.
Title: Re: Lisp in Basic
Post by: JRS on September 25, 2014, 06:22:24 PM
Q. What is the best Lisp language to use?

Lisp Programmer:  I don't know. Everything I've tried so far isn't it.  :o

For the SB project TinyScheme works out great as a BASIC Scheme Lisp extension, It's supported and extensible at the C level to add core functionality. Speed isn't my primary objective with the SB TS ext.

@Mike - Before you abandon the LISP-in-BASIC project, does your updated SBLisp version work?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 25, 2014, 08:16:39 PM
Who said I was updating the SBLisp version all this time? I thought I was working with OxyLISP, judging by my screenshots on the forum... :o
Title: Re: Lisp in Basic
Post by: JRS on September 25, 2014, 09:25:55 PM
If you can send me the code where you left off and I might be able to add some of your improvements to the current posted code base on Bitbucket.

Title: Re: Lisp in Basic
Post by: JRS on September 25, 2014, 09:56:33 PM
I wonder if we can progress on to using Graphics with Scheme/Lisp? What is the standard that most Lisp languages use as a graphics engine and what primitives are supported?

Here is the Script BASIC Mandelbrot example we have used in the past with multiple languages. I would like to see a Lisp example of this.

Code: Text
  1. ' ScriptBasic GFX - Mandelbrot
  2.  
  3. IMPORT gfx.inc
  4.  
  5. s = gfx::Window(640,480,"Script BASIC SDL_gfx Mandelbrot")
  6. ts = gfx::Time()
  7. FOR y = 0 TO 479
  8.   FOR x = 0 TO 639
  9.     cx = (x - 320) / 120
  10.     cy = (y - 240) / 120
  11.     rit = gfx::Mandelbrot(cx, cy, 510)
  12.     gfx::PixelRGBA s, x, y, rit * 32, rit * 16, rit * 8, 255
  13.   NEXT
  14. NEXT
  15. te = gfx::Time()
  16. gfx::stringColor s, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0x000000ff
  17. gfx::Update
  18. WHILE gfx::KeyName(1) <> "+escape"
  19. WEND
  20. gfx::Close
  21.  



 

.
Title: Re: Lisp in Basic
Post by: Charles Pegge on September 26, 2014, 12:01:18 AM
Hi Mike,

Roughly how many core operators are there in NanoScheme?

I am sure there will be several opportunities to reduce the binary size and timings, but that is phase 2 :)
Title: Re: Lisp in Basic
Post by: RobbeK on September 26, 2014, 12:11:59 AM
Hi,

John : as for the graphics, BigLoo , STALIN and GCL come with Japi (and IIRC it is also used with Haskell ).
GCL uses probably an early version, some parts are missing (progress bar - incomplete textarea ...) , STALIN uses a modest subset however because the set up is done by an ini file it can be updated (which is not possible with GCL)  -- I have written the Japi bindings for NewLISP ,CLisp and Closure Lisp.  But most CL's use Tk nowadays ...  http://www.peter-herth.de/ltk/

Mike, where did you download nanoScheme ??  -- the link I found gives a erroneous distribution -- it will not install (windows registery key error --   it tries to do nanAscheme  >:(    Maybe you found it on a Russian site ???
In my native language both Lisp and Scheme are masculin  (but a scheme is neuter )   and like in German a language in general is feminine  -- it's the old language from Brabant , not Dutch -- we use the articles like in German  (der , die , das ) - while Dutch has two (mas/fem the same and neuter ) and English has only one.
The nice thing is, that I can conversate with my friend in Aachen in about the same dialect ..  it is still probably related with the empire of Carolus Magnus (must be strange , because I can not hear any difference between someone from Sankt-Peterburg and Vladivostok ...   )

best Rob


Title: Re: Lisp in Basic
Post by: JRS on September 26, 2014, 12:38:12 AM
Rob,

I'm thinking about adding a extension to TS that would call Script BASIC functions and subs passing arguments back and forth.  8)

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 26, 2014, 05:44:12 AM
Hi,

Some more info on nanoscheme. It compiles perfectly without a single modification to its code by FBSL's DynC but: i) its footprint (48KB) turns out roughly twice larger than 23.5KB when compiled with gcc -Os (optimize for small size); and ii) its speed in DynC is twice slower than when compiled with gcc -Os, but still 50% faster than that of tinyscheme.

And here is nanoscheme's initialization file that will give you some idea what the language is capable of syntactically at its current state:

Code: [Select]
; nanoscheme initialization file

(define (caar x) (car (car x)))
(define (cadr x) (car (cdr x)))
(define (cdar x) (cdr (car x)))
(define (cddr x) (cdr (cdr x)))
(define (caaar x) (car (car (car x))))
(define (caadr x) (car (car (cdr x))))
(define (cadar x) (car (cdr (car x))))
(define (caddr x) (car (cdr (cdr x))))
(define (cdaar x) (cdr (car (car x))))
(define (cdadr x) (cdr (car (cdr x))))
(define (cddar x) (cdr (cdr (car x))))
(define (cdddr x) (cdr (cdr (cdr x))))
(define (caaaar x) (car (car (car (car x)))))
(define (caaadr x) (car (car (car (cdr x)))))
(define (caadar x) (car (car (cdr (car x)))))
(define (caaddr x) (car (car (cdr (cdr x)))))
(define (cadaar x) (car (cdr (car (car x)))))
(define (cadadr x) (car (cdr (car (cdr x)))))
(define (caddar x) (car (cdr (cdr (car x)))))
(define (cadddr x) (car (cdr (cdr (cdr x)))))
(define (cdaaar x) (cdr (car (car (car x)))))
(define (cdaadr x) (cdr (car (car (cdr x)))))
(define (cdadar x) (cdr (car (cdr (car x)))))
(define (cdaddr x) (cdr (car (cdr (cdr x)))))
(define (cddaar x) (cdr (cdr (car (car x)))))
(define (cddadr x) (cdr (cdr (car (cdr x)))))
(define (cdddar x) (cdr (cdr (cdr (car x)))))
(define (cddddr x) (cdr (cdr (cdr (cdr x)))))

(define call/cc call-with-current-continuation)

(define (list . x) x)

(define (map proc list)
    (if (pair? list)
        (cons (proc (car list)) (map proc (cdr list)))))

(define (for-each proc list)
    (if (pair? list)
        (begin (proc (car list)) (for-each proc (cdr list)))
        #t ))

(define (list-tail x k)
    (if (zero? k)
        x
        (list-tail (cdr x) (- k 1))))

(define (list-ref x k)
    (car (list-tail x k)))

(define (last-pair x)
    (if (pair? (cdr x))
        (last-pair (cdr x))
        x))

(define (head stream) (car stream))

(define (tail stream) (force (cdr stream)))

;; The following quasiquote macro is due to Eric S. Tiedemann.
;;   Copyright 1988 by Eric S. Tiedemann; all rights reserved.

(macro
 quasiquote
 (lambda (l)
   (define (mcons f l r)
     (if (and (pair? r)
              (eq? (car r) 'quote)
              (eq? (car (cdr r)) (cdr f))
              (pair? l)
              (eq? (car l) 'quote)
              (eq? (car (cdr l)) (car f)))
         (list 'quote f)
         (list 'cons l r)))
   (define (mappend f l r)
     (if (or (null? (cdr f))
             (and (pair? r)
                  (eq? (car r) 'quote)
                  (eq? (car (cdr r)) '())))
         l
         (list 'append l r)))
   (define (foo level form)
     (cond ((not (pair? form)) (list 'quote form))
           ((eq? 'quasiquote (car form))
            (mcons form ''quasiquote (foo (+ level 1) (cdr form))))
           (#t (if (zero? level)
                   (cond ((eq? (car form) 'unquote) (car (cdr form)))
                         ((eq? (car form) 'unquote-splicing)
                          (error "Unquote-splicing wasn't in a list:"
                                 form))
                         ((and (pair? (car form))
                               (eq? (car (car form)) 'unquote-splicing))
                          (mappend form (car (cdr (car form)))
                                   (foo level (cdr form))))
                         (#t (mcons form (foo level (car form))
                                         (foo level (cdr form)))))
                   (cond ((eq? (car form) 'unquote)
                          (mcons form ''unquote (foo (- level 1)
                                                     (cdr form))))
                         ((eq? (car form) 'unquote-splicing)
                          (mcons form ''unquote-splicing
                                      (foo (- level 1) (cdr form))))
                         (#t (mcons form (foo level (car form))
                                         (foo level (cdr form)))))))))
   (foo 0 (car (cdr l)))))

;; atom?
(define (atom? x)
  (not (pair? x)))

;; memq
(define (memq obj lst)
  (cond
    ((null? lst) #f)
    ((eq? obj (car lst)) lst)
    (else (memq obj (cdr lst)))))

;;    equal?
(define (equal? x y)
  (if (pair? x)
    (and (pair? y)
         (equal? (car x) (car y))
         (equal? (cdr x) (cdr y)))
    (and (not (pair? y))
         (eqv? x y))))


;; (do ((var init inc) ...) (endtest result ...) body ...)
;;
(macro do
  (lambda (do-macro)
    (apply (lambda (do vars endtest . body)
             (let ((do-loop (gensym)))
               `(letrec ((,do-loop
                           (lambda ,(map (lambda (x)
                                           (if (pair? x) (car x) x))
                                      `,vars)
                             (if ,(car endtest)
                               (begin ,@(cdr endtest))
                               (begin
                                 ,@body
                                 (,do-loop
                                   ,@(map (lambda (x)
                                            (cond
                                              ((not (pair? x)) x)
                                              ((< (length x) 3) (car x))
                                              (else (car (cdr (cdr x))))))
                                       `,vars)))))))
                  (,do-loop
                    ,@(map (lambda (x)
                             (if (and (pair? x) (cdr x))
                               (car (cdr x))
                               nil))
                        `,vars)))))
      do-macro)))

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 26, 2014, 06:03:15 AM
Hi John,

Gotcha again. :)

My idea is that I hereby stop developing LISP-in-BASIC's variant of OxyBASIC because it's a dead end by original design and feature completeness, and I will not release its sources in order to keep our environment tidy. Instead, I suggest rebranding OxyLISP based on nanoscheme, which will bring satisfaction both to me and others because OxyLISP will be right off almost as versatile as tinyscheme, equally easy to expand, and much much faster. I believe Oxygen has enough potential to keep OxyLISP's speed compatible with the gcc -Os nanoscheme.

But a few of current OxyLISP's features that are suitable for inclusion in SBLisp will be added to the latter and I'll post its sources here for you to transfer to the repo. You should understand that even so, it's not just a matter of copy-pasting; everything should be tested and it also takes time. Please be patient. If I said I would do it, I eventually will even though it's not on my top priority list.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 26, 2014, 06:22:16 AM
Hi Charles,

Lexicologically, nanoscheme is a complete implementation of R4RS standard of Scheme including its macro and call-with-current-continuation extensions. Numerically, it currently implements 32-bit integers (fixnums) only though its data type UDT and tagging system is easily expandable to accomodate other data types. Perhaps I will turn 32-bit fixnums to 64-bit fixnums (quads) and will add 64-bit flonums (doubles) when porting the code to Oxygen. Full "numeric tower" is possible later on by adding exact, complex, and bignum data types as well.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 26, 2014, 06:44:05 AM
Hi Rob,

I will not disclose where I got the nanoscheme sources from. I can only tell you that "nanoscheme" is my own codename for it and it has nothing to do with its original name. Its author released it in the public domain officially so I am not obliged to name either him or his original creation. Nonetheless, nanoscheme based OxyLISP will go in the public domain as well and it will not bear any mention of my own name there. Perhaps it will even include a tribute to the original author, which, in my opinion, will be more than appropriate (though absolutely not required) under the circumstances.

There are no dialects in Russian. There is only humble speech of the peasantry, marginal lingo of the declassed, mixed parlance of the population that live on the Belarusian/Russian and Ukrainian/Russian borders (like in Donbass, for example), and educated, lofty speech of the intellectuals. The literary language of Saint-Petersburg is a recommended standard for both writing and pronunciation.
Title: Re: Lisp in Basic
Post by: JRS on September 26, 2014, 11:52:36 AM
Quote from: Mike
I will not disclose where I got the nanoscheme sources from.

Lets see if the KGB can make you talk.  :-X
Title: Re: Lisp in Basic
Post by: JRS on September 26, 2014, 01:38:11 PM
What would be the preferred TinyScheme syntax for passing a list to a BASIC array?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 26, 2014, 04:35:37 PM
Lets see if the KGB can make you talk.  :-X

Actually they tried to four times in my life IIRC but failed. It wasn't Stalin's original KGB (called OGPU at those times) though. ;)

What would be the preferred TinyScheme syntax for passing a list to a BASIC array?

It would be OK if general syntax is

(foreign-call <BASIC-foo-name> [<param1> <param2> . . . <paramn>])

foreign-call can also be foreign-function. BASIC-foo-name is the name of the function or sub you're actually calling. Optional param's can be of any type that Tinyscheme can pass and BASIC can accept. Any of the param's can be distinct data objects (separate chars, numbers, strings), char and number vectors (i.e. arrays), or lists containing any of the aforementioned data objects in any combination. A param can also be an expression result, e.g. (+ 2 2) or the name of a variable that refers to any of the aforesaid objects, in which case the variable's value is passed as the actual parameter.

That's what I've seen in the LISP languages so far. Perhaps Rob can suggest something better.


P.S. Lists are usually expressed through the name of the variable that actually refers to the list in question, or through an expression that returns a list, e.g. (list 1 2 3 4 5). An empty list is denoted as () or '() and would evaluate to 0 in such a language as SB. In BASIC's that recognize pointers, an empty list would also evaluate to a void zero pointer, or NULL.
Title: Re: Lisp in Basic
Post by: JRS on September 27, 2014, 12:12:18 AM
Mike,

My question is what is going to be returned from TS in the list argument? A pointer to a C array/structure/... or a delimited string?

SB can't return arrays from a function call. It can pass arrays in whole as an argument (lval) by ref. I would convert the TS list to a SB array and pass it along in the list argument to the SB script function..

Title: Re: Lisp in Basic
Post by: RobbeK on September 27, 2014, 01:49:04 AM
Hi John, Mike

--  all I can find about TS is :

----------------------

+New foreign_ptr type, used to store arbitrary data.
+
+This new type of atom cell allows to store a foreign pointer,
+with an associated finalizer function, used to reclaim any resources
+accessible through the pointer, when the cell is finalized.
+Each pointer has a tag associated with it, which can be used to identify
+the type of resource pointed to.
+
+Definition:
+
+The foreign pointer is stored in the new _fp field of the cell structure.
+
+The _fp field has type foreign_ptr, defined as follows:
+
+typedef void(*finalizer)(void*);
+typedef struct {
+ int _tag; /* Identify your pointer with this. */
+ void* _ptr; /* Store your pointer here. */
+ finalizer _fin; /* Store your finalizer here.
+ This function is called with _ptr as argument when
+ the cell is finalized.
+ Set to NULL if you do not need to release any data. */
+} foreign_ptr;
+
+Accessors:
+
+foreignptr_tag(pointer p) - reference the _fp._tag field.
+foreignptr_ptr(pointer p) - reference the _fp._ptr field.
+foreignptr_fin(pointer p) - reference the _fp._fin field.
+
+Scheme interface:
+
+sc->vptr->mk_foreign_ptr(scheme*,foreign_ptr*)
+ Creates a new cell of type foreign_ptr,
+ and copies to it the fields of the given foreign_ptr.
+
+sc->vptr->is_foreignptr(pointer)
+ Tells wether a cell is a foreign_ptr.

----------------------------------------

Racket Scheme and BigLoo have something as   (make-array-type 'ctype' 'length')  and then use something as ptr-ref to access the elements   (The own Scheme arrays by    vector-ref   and vector-set!  )
If you have a list it has to be converted by (list->vector a-list)   -- as a vector is one dimensional, so should be the list.
or you can travel recursively through the list and assign the foreign array

the problem is that every lisp uses its own foreign function interface --- it's sometimes somewhat frustrating (NewLISP is by far the easiest of them all )

best Rob

 
Title: Re: Lisp in Basic
Post by: RobbeK on September 27, 2014, 06:05:18 AM
Hyper Magic Squares  8)
--------------------------

I found that in a magic square also the diagonals can have the same sum.
(see attached).

Things are getting slow (even by using 4 conditionals (because I can calculate the sum before the actual calculations  ;) )
After all, a 4² square filled with 16 numbers gives 20922789888000 permutations .....  (is there a King around ??)

It only does (not to become boring) 9 solutions    .........

I want to interface it with Oxygen ,   there's no  ..  catch , throw I think ?   -- how do I exit a 16 deep for next loop ????

exit for, for , for , for ... for   (16x)

best Rob

(for those (if) working with NewLISP and want to combine it with Japi , the bindings are included in the source this time )



.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 27, 2014, 08:51:21 AM
I want to interface it with Oxygen ,   there's no  ..  catch , throw I think ?   -- how do I exit a 16 deep for next loop ????

exit for, for , for , for ... for   (16x)

Hi Rob,


Why not use

goto freedom

where freedom is a label immediately outside the outermost for/next?


Every "new" is a well forgotten "past".  ;D

(P.S. By the way, you can do it in FBSL. It allows you to specify e.g. exit level 4 or continue level 2 where level n denotes the nesting depth level you want to jump out to. "Empty" exit for and continue would evaluate to exit level 0 and continue level 0, respectively, i.e. exit from, or continue, the loop you'e currently in. This is very handy when nested deeply in the loops of the same kind -- all for's or do's or while's.)
Title: Re: Lisp in Basic
Post by: JRS on September 27, 2014, 09:09:30 AM
Maybe this idea of TS calling SB is not worth the effort. It would a much better use of my time to get SDL_gfx working with TinyScheme for both the standalone and SB extension module. I'm still trying to get SBT to call a function which would have been a prerequisite to TS calling SB. I hope Charles can shed some light on this issue for me.

 
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 27, 2014, 09:39:42 AM
My question is what is going to be returned from TS in the list argument? A pointer to a C array/structure/... or a delimited string?

Hi John,

TinyScheme should send a pointer (that's a #define that denotes a cell*) to a compound structure cell of the following kind:

/* cell structure */
struct cell {
  unsigned int _flag;
  union {
    struct {
      char* _svalue;
     __int64 _length;
    } _string;
    num _number;
    port* _port;
    foreign_func _ff;
    struct {
      struct cell* _car;
      struct cell* _cdr;
    } _cons;
  } _object;
};


wherein _cons (which means a "pair") is the member that denotes a list. It comprises two members:

1. a cell* member (in fact, another pointer) called _car that would point to a structure cell which is the list's first element (of whatever type); and

2. one more cell* member called _cdr that would point to yet another list that hosts the list's other elements (those can also be of whatever type).

That said, from the C language perspective a TinyScheme list is a tree-like linked list of cell structures each of which can represent any typedef -- a _string, a num, a port, a foreign_func, or yet another _cons, i.e. a pair (2-element list) where _car is the list's first element, and _cdr is still another list of its other elements.

The type of data that a given cell represents is coded in its _flag member. See scheme.h for what num and foreign_func look like, and scheme-private.h, for cell and port structures.


P.S. Yes, interfacing TinyScheme with SB seamlessly would require profound knowledge of C. It's up to you to decide if it's worth your effort.
Title: Re: Lisp in Basic
Post by: RobbeK on September 27, 2014, 09:50:21 AM
Hi Mike,

GoTo -- (traumatic experiences)  , we were caned when using it   ;D

but ok , when you have to go , you have to go

(are the indices / return addresses (?)  of the loops reset / cleared by doing it this way ? )

(dark secret :   even Common Lisp has (go    )     8)

forgot to mention : the magic4 needs around 30sec (on my 'puter) to find the first solution -- but then it starts cascading ...

best, Rob
Title: Re: Lisp in Basic
Post by: JRS on September 27, 2014, 09:59:50 AM
Quote from: Mike
Yes, interfacing TinyScheme with SB seamlessly would require profound knowledge of C. It's up to you to decide if it's worth your effort.

Lisp is a novelty language for me and if it wasn't for SBLisp and then TinyScheme, I would have moved on long ago. It pains me to see Rob stuggling with JAPI as the standard for a Lisp GUI when SDL is a much better cross platform solution.

I need to master SB internals before taking on any other languages that are a peripheral interest in my realm.   
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 27, 2014, 10:17:15 AM
Rob,

A goto is a must in any language. There's nothing better and faster than goto when used intelligently. But it must be a ban for novices and dumbheads.

Oxygen's goto evaluates to a jmp instruction, and for/next evaluates to a label/jmp label loop. There is nothing that you could possibly spoil by jmp-ing out of a loop within a loop within a loop etc. Garbage collection is done at the end of the current procedure but you can't goto (i.e. jmp) out of the procedure so everything's gonna be alright, babe. :)

See also my P.S. to my previous message.


P.S. It takes my PC only 5 seconds to get the first box solved. :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 27, 2014, 10:27:46 AM
I need to master SB internals before taking on any other languages that are a peripheral interest in my realm.

Technically speaking, there's no difference between the SB and TS internals since both are written in ANSI C. The only major task is to figure out how well TS' cell's fit in SB's variants and add proxy interfaces and/or macros and/or functions that would do the job if they don't. That's what an SB developer, not a TS developer, should do.
Title: Re: Lisp in Basic
Post by: JRS on September 27, 2014, 10:46:05 AM
Until the SBT  extension module is working, I have no interest in anything else. I have been trying to get cross platform scriba threading working since I took over managing the project. Peter (sbhttpd) and Charles (DLLC) are the only SB masters that have partied at the summit.  8)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 27, 2014, 11:28:01 AM
Quote from: John
It pains me to see Rob stuggling with JAPI ...

JAPI is evil by design, implementation, and behavior. There's nothing worse on my PC than JAPI since it appeared there when Rob started posting his LISP/JAPI executables here.

For example, no magic square executable can be stopped or aborted until the calcualtion ends, due to the tight loop in which LISP calc runs. You can only click the console [X] button that would seemingly kill the process. You can then freely delete his japi.dll but you still can't delete his magic.exe from your PC until you reboot! It is reported as still being used by some mysterious process, and the Task Manager or Process Explorer would show you that the JAPI process and all its paraphernalia are still hanging in your memory despite the application console having been irreversibly closed, and the JAPI server, deleted! So, you have to kill the JAPI process by hand in order to be able to delete magic.exe from your disk.

I would gladly tear the arms and other extremities off of those (Java) developers whose product behaves like that on my machine.
Title: Re: Lisp in Basic
Post by: JRS on September 27, 2014, 12:35:44 PM
Quote from: Mike
I would gladly tear the arms and other extremities off of those (Java) developers whose product behaves like that on my machine.

Please let me have first shot at maiming those responsible for Java theme support in JRE.  ;)
Title: Re: Lisp in Basic
Post by: RobbeK on September 27, 2014, 12:51:37 PM
Hi John , Mike ,

I did not program any event interception in the main calculating loop --  the [X] is not a meta-key as under Windows , I have not only to code its behaviour , but make it conceptual  ...

I added a listener into these loops now ,   consequently to end the program you will have to push it twice ..  of course if any of the mentioned evils are still manifest, I'll stop using Japi as an interface.   Pushing twice should free/remove the DLL and remove NewLISP as any running task ...

best Rob and thanks in advance  ;)
(closing the console , probably is a conflicting way --  I'll hide it (if any further use of Japi) in the future.
 

.
Title: Re: Lisp in Basic
Post by: JRS on September 27, 2014, 02:02:34 PM
Rob,

I think I have a generic version of the SB wrapped SDL_gfx I created for BaCon before the author turned info an ass-hole. I can't remember if I compiled it for Windows and used it with DLLC. If there is any interest in SDL_gfx, I'll look around for it.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 27, 2014, 02:54:30 PM
No Rob,

Your new exe behaves as badly as the previous one. Once loaded, javaw keeps hanging in memory irrespective of how you quit newlisp. You can even:

1. abstain from starting to calc the magic squares (i.e. from pushing the go! button);

2. close the graphics window by its [X] button thereby getting access to your newlisp console input/output; and

3. then you can type (exit) in the console in an attempt to quit the entire process.

Nonetheless, even if your console closes on this command, javaw still persists in memory eating resources and making the magic.exe file undeletable from the disk. (NB item 2 above is the exact situation that I showed how to cope with in my earlier Non Blocking Console example)

This mess breaks the fundamental rules of Windows programming:

1. Any GUI process must be killable completely by destroying its main window (Alt+F4 press or [X] click or DestroyWindow()) so that javaw must unload once its main window closes; and

2. Every console or shell process on an NT platform must be killable cleanly and completely (i.e. killing also all dependent processes, whether CUI or GUI, such as javaw in our case) once the shell or process console window is closed with a [X] button click or exit command.

So your NL/JAPI executables are breaking both of these rules simultaneously, and this isn't your fault. This is the unpardonnable fault of NewLISP and Java for Windows developers who don't know their whereabouts on the platform they are claiming compatibility with. >:(
Title: Re: Lisp in Basic
Post by: jack on September 27, 2014, 03:42:24 PM
hello RobbeK,
have you tried the gui server of newlisp?
there are a number of examples in the demo folder, goto help/open demo folder.
Title: Re: Lisp in Basic
Post by: JRS on September 27, 2014, 04:02:40 PM
Rob,

If the CERN ROOT graphics API and GUI builder fits for the type of stuff you do, there is a Lisp interface library that comes with the package.

As popular as Lisp seems to be, you would think they would have GUI figured out by now.  :-[
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 27, 2014, 07:01:40 PM
Hey guys,

nanoscheme does 64-bit integer calc. (wink-wink John)

Proceeding straight over to flonums. :)

.
Title: Re: Lisp in Basic
Post by: JRS on September 27, 2014, 07:35:32 PM
Cool Mike.

Is source to your creation going to be made available?

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 27, 2014, 07:56:58 PM
http://www.oxygenbasic.org/forum/index.php?topic=1147.msg11587#msg11587 (http://www.oxygenbasic.org/forum/index.php?topic=1147.msg11587#msg11587)

Currently it's still in its C form. It'll be easier to translate it to Oxygen all in one piece with all these minute improvements already in place.
Title: Re: Lisp in Basic
Post by: JRS on September 27, 2014, 08:51:10 PM
We all can be thankful that you stayed the Scheme path and didn't cheat and use other Lisp varieties like Rob.  :P

Sooner or later Rob will catch on to our scheme.  ::)

Q. Am I sounding like a Lisp programmer yet?
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 27, 2014, 11:04:14 PM
A. No, not yet. You should be consing and memoizing more often. You should also abstain from subs and functions and stick to lambdas and closures.

Good night!

(http://www.fbsl.net/phpbb2/images/smilies/icon_ml_gnight.gif)
Title: Re: Lisp in Basic
Post by: RobbeK on September 28, 2014, 12:42:29 AM
Morning, Jack , John , Mike ...

OK, the problem is there with all progrs running Japi, be it as a static lib or dynamic.
I tested : FB , STALIN and some others ..  it does not remove its Java launcher on exit.  -- On the web similar behaviour is mentioned concerning Eclipse , Minecraft applications and others.
Under NewLISP it is even worse (as Mike mentioned)....
From what I read it seems the Java code misses     exit(0)   to make the launcher not resident....   

Good,  (or better bad )   ...   NewLISP with its own Java (Swing) server , closes things normally.
(However (Jack) , while the server has tagged graphics , it misses pixel drawing and (AFAIK) any memory->screen mechanism making fast animations possible ....     (sigh)

So, John ... what I'm looking for is something doing fast double buffered graphics and/or uses OpenGL -- you're 100% correct the combination Windows + Lisp + Graphics is a close to disaster situation ...   (all seem focussing on Unix systems )

best , Rob

.................  copy from the www

After invoking and closing a random chosen java web start application (e.g. from http://java.sun.com/products/javawebstart/demos.html) javaws.exe stays in memory
(e.g. end of the day 10 copies of javaws.exe in Windows Task Manager)

-----------  it seems their own demo's show this behaviour (ok , it's old stuff , but  ....  )

(I think the best solution is to concentrate on Racket Scheme , which has a perfect GUI builder , OpenGL and the code compiles both under Win and Linux )


(Mike, is their a "software-way" to remove tasks ?? )
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 28, 2014, 04:04:59 AM
Hi Rob,

If NL allows you to easily call Windows DLL functions then try to call ExitProcess(0) which resides in kernel32.dll. It has the same effect as exit(0) and it also closes all of the process' own dependencies gracefully. It is the preferred method of ending a Windows process. This function provides a clean process shutdown. This includes calling the entry-point function of all attached dynamic-link libraries (DLLs) with a value indicating that the process is detaching from the DLL. After all attached DLLs have executed any process termination value, this function terminates the current process.

Quote from: Win SDK Help
VOID ExitProcess(
    UINT uExitCode    // exit code for all threads 
);

Terminating a process however does not cause child processes to be terminated. So, if for some reason javaw.dll isn't used as an ordinary in-process code module but rather spawns a separate process of its own, it might stay resident as it does now. (but that would be unusual and incorrect under Windows)

If it doesn't help, a more complicated WinAPI strategy should be followed. This would involve enumerating all running processes to find the javaw process handle and applying a rougher TerminateProcess() WinAPI directly to javaw. That's effectively what the Task Manager does when I push its Kill Process button with javaw selected in its list of currently running processes:

Quote from: Win SDK Help
BOOL TerminateProcess(
    HANDLE hProcess,   // handle to the process
    UINT uExitCode    // exit code for the process 
);

I don't however know if the latter strategy is suitable for programs that have been launched without Admin privileges on Vista+ platforms.


P.S. Judging by your quotations from other people, javaw behaves like downright malware. I wonder if it is also being developed by yet another bunch of GNU GPL open-sourcers? ;)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 28, 2014, 04:49:36 AM
Hehe, look: John's already emitted 2,000 messages! That's about 1/5th of the forum's total.
Title: Re: Lisp in Basic
Post by: RobbeK on September 28, 2014, 05:22:36 AM
Hi Mike,

(import "kernel32.dll" "ExitProcess")

and

(ExitProcess 0)

but it doesn't kill javaw.exe  >:(


malware , yes .. a perfect definition   --- another one from the www

--------------   AD 2012



Recently, javaw.exe processes have been taking over my computer and forcing me to exit out Eclipse and other applications due to low memory errors. Note that I am not maxing out the system at all, and am I working on some basic java programs, and I have 2-3 eclipse tabs open at a time max.

I have about 40-50 of these javaw.exe processes each take up 22K-26K of RAM, which eventually eats up 70-80% of my 8GB RAM on my machine. This is extremely frustrating as I cannot do any work like this. I was wondering if anyone else has experienced this and knows how to troubleshoot this problem?

--------------------------------------  AD 2014

"javaw.exe memory usage increases constantly"

---------------------------------

No answers from Sun or Oracle ................

best Rob

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 28, 2014, 07:14:03 AM
Rob,

Then there is only one way out, which is to use TerminateProcess() on javaw.exe. I will give you some OxygenBasic code below (not tested though, it's my immediate port from FBSL!) that will loop to find the Java process and kill it. You will have to translate it to NL if it supports C/O2 style structures/UDT's, or you will have to compile it as an O2 executable and launch your NL/JAPI apps from a batch (.BAT) file wherein the first line should shell out to your NL/JAPI exe, and the second should run this O2 proggy. It will be killing Java automatically once your NL/JAPI app terminates.

Code: [Select]
! Function CreateToolhelp32Snapshot LIB "kernel32" (DWORD dwFlags, th32ProcessID) As DWORD
! Function Process32First LIB "kernel32" (DWORD hSnapshot, lppe) As Long
! Function Process32Next LIB "kernel32" (DWORD hSnapshot, lppe) As Long
! Function OpenProcess LIB "kernel32" (DWORD dwDesiredAccess, bInheritHandle, dwProcessId) As DWORD
! Sub TerminateProcess LIB "kernel32" (DWORD hProcess, uExitCode)
! Sub CloseHandle LIB "kernel32" (DWORD hObject)

Type PROCESSENTRY32
  DWORD dwSize
  DWORD cntUsage
  DWORD th32ProcessID
  DWORD th32DefaultHeapID
  DWORD th32ModuleID
  DWORD cntThreads
  DWORD th32ParentProcessID
  Long pcPriClassBase
  DWORD dwFlags
  Char szExeFile[260]
End Type

Const TH32CS_SNAPALL = 0xF
Const PROCESS_TERMINATE = 0x1

Dim lppe As PROCESSENTRY32
Dim As DWORD hproc, hsnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0)
Dim As Long success

If hsnapshot Then
    lppe.dwSize = SizeOf(lppe)
    success = Process32First(hSnapshot, @lppe)
    While success
        If RTrim(lppe.szExeFile) = "javaw.exe" Then
           hproc = OpenProcess(PROCESS_TERMINATE, 0, lppe.th32ProcessID)
           TerminateProcess(hproc, 0)
           CloseHandle(hproc)
           Exit While
        End If
        success = Process32Next(hsnapshot, @lppe)
    Wend
    CloseHandle(hsnapshot)
End If

End


This script has just shot dead that hateful javaw.exe process left over from your recent magic4b.exe. :D

P.S. DO NOT try to use the EnumProcesses() WinAPI as many would suggest out there -- this WinAPI is hosted in different DLL's on different platforms, so your code won't be platform independent then.
Title: Re: Lisp in Basic
Post by: RobbeK on September 28, 2014, 10:18:46 AM
Thank you so much Mike  --  the only other solution was to throw away BigLoo and the STALIN compiler (starting up the TaskManager after every run, is doing things wrong imho - even if this works)  , Japi being their only interface under Windows.  (same for GCL in fact )

Yes, NL has C structures to interface with foreign (C) functions (and unlike some Common Lisps , it uses c-strings ).  I'll add it to the system naming it (exit0) or something like ...

...  thanks again  :)

Been toying with the Guiserver.jar that comes with the NL distribution,  here at first sight , I do not see any problems  -- (the console nicely outputs it shuts down the server )

However, now it seems it gives problem under the OpenJava (or GNUJava or whatever ) on Linux .... ::)   never mind ...

(it has a more modern look/feel , even with some themes and the graphics are tagged )


best, Rob



.
Title: Re: Lisp in Basic
Post by: JRS on September 28, 2014, 10:23:22 AM
Quote from: Rob
So, John ... what I'm looking for is something doing fast double buffered graphics and/or uses OpenGL -- you're 100% correct the combination Windows + Lisp + Graphics is a close to disaster situation ...   (all seem focussing on Unix systems )

If the folks at CERN, NASA, ... thought Windows was a better OS to use for their research, they would be using it but their not. Don't forget that buying commercial business software isn't just about code but getting paid and hooking you on the solution as long as they can bleed you. (vendor lock-in) It won't be long before the concept of selling software seems absurd. Profit should be made on services provided and custom adaptations of the norm.
Title: Re: Lisp in Basic
Post by: RobbeK on September 28, 2014, 12:18:52 PM
Hi John,

NASA  ..   
http://www.nas.nasa.gov/quantum/quantumcomp.html

OS controled by Steel Bank Common Lisp -- interfacing language proposal/actual situation(?)  : Python --  exactly  Aurel's top two of weird languages (he used another word, but do not remember it) .  Nasa's CLIPS (not CLisp) can be downloaded IIRC (complete with manuals etc ... )    ..   I had a friend at NASA , .. Kevin , 
“Wen die Götter lieben, der stirbt jung”  ...   ,,    (those loved by the Gods, die young  -- or something like ) 

best Rob

   
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 28, 2014, 04:37:13 PM
Hi John,

You could've started your new millennium with something better than advocating again in favor of a GNU GPL OS for microwave ovens and vacuum cleaners. See what your pimply "community efforts" are doing to the decent people's computers?! >:(
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 28, 2014, 04:41:40 PM
No Rob,

Your exe misses something else for running on my PC. It's a regular announcement that "/newlispam" (whatever it is) isn't an internal or external command, executable program, or batch file. :-\

.
Title: Re: Lisp in Basic
Post by: JRS on September 28, 2014, 05:43:17 PM
Hi John,

You could've started your new millennium with something better than advocating again in favor of a GNU GPL OS for microwave ovens and vacuum cleaners. See what your pimply "community efforts" are doing to the decent people's computers?! >:(

I make my living supporting clients needing business software. Most of what I do is web and server related. I'm sure Windows is fine for everything else.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 28, 2014, 11:57:10 PM
Thanks, John. You are forgiven. 8)
Title: Re: Lisp in Basic
Post by: RobbeK on September 29, 2014, 12:48:47 AM
hi all,

/newlispam ...   no idea , it's bundled with the standard mechanism for it  ???

attached without any bundling and a batch file named go.bat   ...   (maybe this works)


best Rob

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 29, 2014, 02:07:16 AM
No Rob,

It doesn't work either for the same reason. Maybe it's some language pack for NL as in /newlisp american? No idea really.

Another quirk by the same unprofessional bunch.
Title: Re: Lisp in Basic: Bug in Scheme.c
Post by: Mike Lobanovsky on September 29, 2014, 04:24:43 AM
Hi John,

There was a bug left in my scheme.c sources concerning number input in binary notation. Please goto somewhere near line 552:
Code: [Select]
  static __int64 binary_decode(const char* s) {
    long x = 0; // <== !!! WRONG !!!
   
    while (*s != 0 && (*s == '1' || *s == '0')) {
      x <<= 1;
      x += *s - '0';
      s++;
    }
    return x;
  }
and change long x = 0; to __int64 x = 0LL;.

Sorry for having overlooked it before. Binary isn't my preferred notation. :)
Title: Re: Lisp in Basic
Post by: jack on September 29, 2014, 04:39:31 AM
hello RobbeK,
there appears to be a hard coded link to the guiserver in the newlisp installation directory, if you create a folder named newlisp in c:\Program Files with the guiserver.jar in it, then your magic program runs OK.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 29, 2014, 05:30:16 AM
Sorry Jack,

But this still doesn't work for me.
Title: Re: Lisp in Basic
Post by: RobbeK on September 29, 2014, 05:36:14 AM
Thanks Jack ..

Found it in the documentation now ,  during installation the specific location is written in the registry (under Win) , in my case d:/newlisp     -- if it find nothing then c:/program files/newlisp is used --  this is written in the NEWLISPDIR variable when NL starts up -- not needed for DLL's, but the location of the JAR has to be specified by it ...   

mm, makes things somewhat complicated , I can overrule the NEWLISPDIR , but how to find out the location were the code is actually running (can be a temp. location when unzip+run in one flow )...   the Racket Scheme solution may be the best ,

launcher (from source) / stand alone / distribution (for an alien computer)   -- needs a kind of installer/uninstaller then, ...

best Rob

ps  :  the number of magic SQ's seems to be  2(s!)²  -- for an s*s square s! being the possible permuations of the lines or rows ...  the sum of row/column    ...  s(s² + 1 )/2    (sum of all numbers in the square divided by s)  -- when you see red in the app, then also the diagonals have this sum.  (not been googling about this yet , more fun this way )
Title: Re: Lisp in Basic
Post by: RobbeK on September 29, 2014, 05:38:46 AM
Mike,

newlisp is located d:/newlisp here , but I thought this information was computer specific

-------------------

guiserver.lsp expects the server guiserver.jar to be in the directoey specified in the environment variable NEWLISPDIR. When newLISP starts up and this variable is not set yet, it sets it to a default value of /usr/share/newlisp on MacOS X and Unix OSs, and to C:\Program Files\newlisp or whatever it finds in the PROGRAMFILES environment variable on Win32 systems and adding /newlisp to it. This can be overwritten by specifying system wide setting for the environment variable NEWLISPDIR, which normally is set to %PROGRAMFILES%/newlisp on Win32. When using the Win32 binary installer NEWLISPDIR is written to the registry automatically and gets into effect after rebooting.

----------------------


best Rob  (possibly Jack has NL installed ?)
Title: Re: Lisp in Basic
Post by: JRS on September 29, 2014, 10:33:25 AM
Quote
Sorry for having overlooked it before. Binary isn't my preferred notation.

Mike,

Does this effect the Windows version only? The Linux version using gcc compiles clean out of the box.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 29, 2014, 11:46:28 AM
John,

Everything compiles just fine OOTB everywhere, but the dormant bug is there nonetheless. long x is too short to accumulate a __int64 return out of sixty four binary bits.

Please do just what I'm asking you to, will you? :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 29, 2014, 11:51:39 AM
Rob,

Needing a registry entry to just run an occasional .jar is ridiculous. If they can't fix their software to make a standalone .exe runnable on a random PC without special installation and hardcoding, then this software is certainly not for me.

I regret to say so but that's how it is.
Title: Re: Lisp in Basic
Post by: JRS on September 29, 2014, 12:00:48 PM
JAPI is like PHP. Patched and holes ignored until it became a standard.  :-[
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 29, 2014, 12:20:04 PM
Gentlemen,

Here comes a preview of the nanoscheme proto still coded in C. But now it is equipped with 64-bit integer and double precision calculus. It comes with its initialization file and three test scripts which you know very well. There is also my timeit.exe inside that you can use to benchmark nanoscheme's speed against e.g. tinyscheme.

Please note that nanoscheme cannot read its command line yet. So, in order to benchmark a particular script, proceed as follows:

1. Open nsinit.scm and uncomment a corresponding (load "xxx") command at its end;

2. Open the corresponding "xxx" test script and uncomment (quit) command at its end; and finally

3. Open up your shell console, cd to the directory where your nanoscheme zip has been decompressed, and type timeit nanoscheme at the prompt. As nanoscheme launches, it will load its nsinit.scm file automatically, execute the (load "xxx") command within, load and run the file "xxx", and quit back to the prompt. There and then you will see the benchmark results printed automatically in your shell console window.

On my PC, nanoscheme is typically 3 times faster than tinyscheme regardless of CPU or FPU calc in relatively long tests such as e.g. the doubly recursive fibonacci(35). asciim runs 5 times faster in nanoscheme than in tinyscheme.

Note that nanoscheme's 64-bit double precision is also much better than that of tinyscheme. Open up the king script and change its parameter at the top of the page to see and compare how it runs with 64-bit integer and double precision.

Be forewarned however that it currently only supports +, -, *, and / arith operators. A complete range of R5RS math, pow, exp and trig operators and functions will be added when ported to OxygenBasic.

Until then, enjoy!

.
Title: Re: Lisp in Basic
Post by: RobbeK on September 30, 2014, 03:05:12 AM
Looking promising, Mike  ;)

(no vectors ??  - planning these in the future ? )

As for the M squares -- converted it into Racket Scheme ..  (attached / compiled as a distribution -- huge file ... this should work )


best Rob


.
Title: Re: Lisp in Basic
Post by: Charles Pegge on September 30, 2014, 03:41:00 AM
I wonder if it would be useful to create a Lisp-friendly GUI, as a DLL. All values could be exchanged in string (char*) form, so that communication would be as simple as print and input.

For example:

_print  "mouse?"
input response:
"220 300 1 0 0 0" 'x y lb mb rb wheel

Geometry:
_print "Vert3  a 0 0 0  1 0 0  1 1 0  0 1 0  0 0 0 face b 0 1 2 3 "
Title: Re: Lisp in Basic
Post by: RobbeK on September 30, 2014, 06:32:07 AM
Such should be great Charles, I tried a lot , many seems either problematic, some (that's a personal view) oversized and introducing classes and objects "ad absurdum"   

John ,

"JAPI is like PHP"   -- maybe (I hope not) :  "japi is like java"   --  I've a Lisp editor written in Java somewhere lying around, it does the opposite from that javaw exec.  --  sometimes it vanishes , gone in a moment  ;D  --    and some the things : it may crash on Ctrl Z   (the undo undo   key)  ...
It is remarkable that after all these years Mike seems the first to notice the "hanging task"  -- japi is used in German univ's , also saw it in a Göteborgh app -  STALIN --  INRIA in France ...  that's 1000s of scientists ...    or is it that old, that things under Win OS changed (seems not likely) ...

best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 30, 2014, 08:58:28 AM
Hi Rob,

Looking promising, Mike  ;)
It doesn't "looks", it "works"! 8)

Quote
(no vectors ??  - planning these in the future ? )
Those GNU GPL gangs have been in for their Lisps for decades only to generate terrible heaps of bloatware that's non-responsive and crashy under Windows. I've been at nanoscheme for less than a week, and it does everything (and more) that it was supposed to do by its original author but didn't.

Since all its data typing mechanism is now polished and verified by adding long longs and doubles, including yet more data types becomes a pure routine of adding respective token types in one place, parser procs, in another place, and handler procs, in the third place. Just as simple as that. Given sufficient interest or insentive, yes, I can add chars and vectors easily in the future.

Quote
(attached / compiled as a distribution -- huge file ... this should work )
Yes, this time it works but again, at the cost of a 15MB installation and two non-responsive windows -- a console and a tiny graphics "window leaf". I had to use my Task Manager to stop and kill the program again.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 30, 2014, 09:14:54 AM
Hi Charles,

I wonder if it would be useful to create a Lisp-friendly GUI, as a DLL. All values could be exchanged in string (char*) form, so that communication would be as simple as print and input.

It's a pity O2 doesn't have an own set of ready-made high-level graphics primitives like PSet, Line, Circle, etc. Since nanoscheme is going to be natively Oxygen-ated, I don't see any reason for a standalone DLL GUI. It should all be integrated as an include file and implemented as direct internal graphics procedures (print a b c ...), (line a b c ...), (arc a b c ...), etc for the graphics part, and (button name a b c ...), (slider name a b c ...), (textbox name a b c ...), etc. for control placement on the GUI form, with their associated (progress-step name a), (text-color-flags fore back transparent), etc. helpers, just to name but a few.

And of course, all this should be built around a non-blocking console.

Simple, efficient, elegant, and fast. Business MS Windows style. No more amateurish "community" mess -- been there, seen that.
Title: Re: Lisp in Basic
Post by: JRS on September 30, 2014, 09:27:44 AM
Quote
No more amateurish "community" mess -- been there, seen that.

I think you are confusing the open source community effort with hobbyists refining their programming skills. Many of the successful open source projects are made up of professional programmers that by day work for some company on a limited scope project and unleash their unrestrained talent toward open source for fun.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 30, 2014, 09:41:01 AM
I am NOT confusing anything. Their "fun" is at the expense of my grief over my lost data and broken hardware. In such a "community", the left hand hardly ever knows what the right one is doing, and vice versa. For as long as there is no official in charge of the project that risks his name, career, and social status being materially responsible for the shitcode that his gang emits, there is no quality code nor product. Naturally self-appointed "managers" and "project leads" don't count in here.

History is made by leaders and individuals, not masses.
Title: Re: Lisp in Basic
Post by: JRS on September 30, 2014, 09:52:21 AM
Quote
History is made by leaders and individuals, not masses.

History has shown that dictators control the masses and are not leaders.
Title: Re: Lisp in Basic [off-topic]
Post by: Mike Lobanovsky on September 30, 2014, 10:01:21 AM
Rob,

I'm sorry for having misled you about the features of MS HTML Help. It can't decompile the old Win'95-style WinHelp files. It can only convert the older .HPJ projects to newer .HHP (CHM-style) projects losing some important features in the process. You will need 3rd-party SW for decompilation. There is some but not much of it is functional with large .HLP files such as e.g. Win32.hlp from the old Windows SDK. It contains a 50MB RTF source file that almost none of the modern "community" software can handle. Even MS' own WinWord 2010 takes about 20 minutes to read in, parse, and convert to a readable form an RTF file of such size, and another 20 minutes or so, to save it as a simple .HTM.

Yet I'm hoping to provide you with a viable solution because I also have a ton of old .HLP files that I can't take along from my XP to my Win 7 -- it can't read these files at all.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 30, 2014, 10:12:23 AM
History has shown that dictators control the masses and are not leaders.

I'm not talking about dictators - they are largely self-proclaimed entities that don't give a damn about anything but their own pocket. I've been living under a dictatorship for the past 20 years myself and it looks like I might well be in for another such 20 year spell.

Meet "the last dictator in Europe" here. (http://www.fbsl.net/phpbb2/viewtopic.php?f=25&t=2788#p9435)

I'm talking about responsible leaders and unwearied workhorses like Theodore Roosevelt or Sir Winston Leonard Spencer-Churchill, for example. ;)
Title: Re: Lisp in Basic
Post by: JRS on September 30, 2014, 10:38:46 AM
Quote from: Rob
“Wen die Götter lieben, der stirbt jung”  ...   ,,    (those loved by the Gods, die young  -- or something like )

Words to die by.
Title: Re: Lisp in Basic
Post by: RobbeK on September 30, 2014, 01:18:44 PM
 "responsible leaders and unwearied workhorses like Theodore Roosevelt or Sir Winston Leonard Spencer-Churchill"

I can not , and never will call someone as Churchill and p.e. Bomber Harris responsible --  it are just war criminals , despite the myth and propaganda set up around them ...

 "History will be kind to me, for I intend to write it"          ...  Sir W Churchill   

"The truth about the real Churchill—the Churchill that few know—is that he was "a man of the state: of the welfare state and of the warfare state" in Professor Ralph Raico's turn-of-phrase. The truth about Winston Churchill is that he was a menace to liberty, and a disaster for Britain, for Europe, for the United States of America, and for Western Civilization itself."  (Adam Young)

(I mentioned Bomber Harris, because in the 80s, 90s ?  the Iron Lady herself rewarded him with a statue for his Dresden massacre , but again this is very related with W Churchill who praised such actions -- though in this case he for a moment started to talk about the Americans ...

"Churchill attempted to disclaim responsibility; even casually saying "I thought the Americans did it.""

best Rob   (my excuses , but I had to tell -- i do not believe in Hitlers Stalins Churchills Kennedy's Kings & Popes )

Title: Re: Lisp in Basic
Post by: JRS on September 30, 2014, 01:58:01 PM
Quote from: Rob
my excuses , but I had to tell -- i do not believe in Hitlers Stalins Churchills Kennedy's Kings & Popes

Your forgot the Bush clan.

Title: Re: Lisp in Basic
Post by: RobbeK on September 30, 2014, 02:22:56 PM
Your forgot the Bush clan.


that's a kind of its own, consequently it needs other kind of words,    ....  but mother and father told me not to (even) whisper such  in public  8)     
Title: Re: Lisp in Basic
Post by: JRS on September 30, 2014, 02:36:24 PM
Not unless you want to end up as a pile of dust.  :-X
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on September 30, 2014, 04:18:05 PM
Rob,

I think most of what you told us is just due to the German language being more of a mother tongue kind for you than English. My father went to the war a second lieutenant of infantry in September 1941 and came back a captain in February 1945. Alive and whole. One out of one hundred of his coevals born in the year of 1924.

I don't mean to be personal but we often take after our parents somewhat more than we should. As for me, I don't rely in such matters on what's written in the books. It turned out so I grew up in one hell, the USSR, and I'm going to die in another, Belarus. I have my own experience that's more than enough for me. And I'm still living only 30 miles away from the Ukrainian border now.

There weren't only British aircraft (and moreover, not so much British aircraft) that were bombing Dresden that day, by the way. On the other hand, Dresden was the place where my second wife grew up. She was a Belarusian girl speaking Russian and making friends with Germans. "And they lived happily ever after", hehe...

Churchill, Thatcher, the Bushes, and Obama into the bargain taken together, with all their pros and cons, are kindergarten children against the other characters of today. Churchill said: the Fascists of the future will be calling themselves anti-fascists.

Putin. Lukashenko.

Year 1995, city of Grozny, Chechnya, Russian Federation. Not an enemy territory; it's been Russia's own territory for the past 200 years. The estimated total of peaceful citizens killed by Russians in this massacre alone ranges from 70 to 200 thousand people. The exact figures are classified. The dawn of Putin's era:

(http://img0.joyreactor.cc/pics/comment/%D0%AF-%D0%92%D0%B0%D1%82%D0%BD%D0%B8%D0%BA-%D1%80%D0%B0%D0%B7%D0%BD%D0%BE%D0%B5-%D0%B2%D0%B5%D1%80%D0%B4%D0%B5%D0%BD%D1%81%D0%BA%D0%B0%D1%8F-%D0%BC%D1%8F%D1%81%D0%BE%D1%80%D1%83%D0%B1%D0%BA%D0%B0-1244263.jpeg)

(http://levoradikal.ru/wp-content/uploads/2013/11/caa6zsg2gMI.jpg)

(http://www.grozniedni.ru/upload/1395347162_author_photo.jpg)



So, beware.
Title: Re: Lisp in Basic
Post by: RobbeK on October 01, 2014, 12:20:39 AM
Hi Mike,

This is my country :
http://www.youtube.com/watch?v=cGWdshofk3s

After a century, yearly still around 300 tons of ammunition surfaces ..  it's one big graveyard.  (and they learned nothing)

----

(I think also Putin was stationed in Dresden in the 80's ??  )

best, Rob

Problem with the tight loops (more or less) solved -- added an exit button and 1 mSec delay in the inner loop -- still problems with the window [X] .. runs a lot faster than NewLISP

 

.
Title: Re: Lisp in Basic
Post by: RobbeK on October 02, 2014, 01:28:15 PM
HI all,

started to study the differences between Scheme and CL now (so , I do not have to do translations in the future ).

It's very powerfull

:   the closures    (p.e. making a function-trampoline)  // i normally used expansions for this ....

(define trampoline
  (lambda (n)
    (lambda (x)
        (+ x  n))))

(define ++ (trampoline 1))  ;; a function generated by another function

(++ 2) -> 3

-------------------------
the "hygienic" macro's

(define-syntax-rule (inc x)   ;; u can't do this with (define ... ) the returned value will be exact , but the variable is not updated
  (set! x (+ 1 x)))

(define a 2)
(inc a)
a -> 3

----------------   8)    nice !

best Rob

p.s.
in this case the (++ ) can be used in recursive mechanisms , the (inc ) in iterative ones : pe in a named let

(define (tst x)
  (let loop ((i 0) (n x))
    (if (= i x) n
        (loop (++ i) (+ i n)))))
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 02, 2014, 05:37:23 PM
Hi Rob,

1. (define trampoline ...)/(define ++ ...) /(++ 2)->3 works OOTB in both tinyscheme and nanoscheme.

2. (define-syntax-rule) is unknown to either tinyscheme or nanoscheme. Are you sure it belongs to R5RS rather than to R6RS?
Title: Re: Lisp in Basic
Post by: RobbeK on October 02, 2014, 11:26:38 PM
Hi Mike,

I'll have to look it up , I'm studying Racket Scheme --  : 
the non-hygienic way should be

(define-macro (inc x)
  (quasiquote (set! ,x (+ 1 ,x))))

which is identical with CL --  the problem here is that  ,x may intercept the wrong value if x is already declared global  -- what should the code do ??   p.e.

(define x 77)

(define-macro (inc x)
  (quasiquote (set! ,x (+ 1 ,x))))    ;; which x to use , the local or the global  ,x stands for (eval x) .....  to avoid this Scheme set up the "hygienic" macro's -- but as I'm new to Scheme , I'll have to look this up (this evening)  GM+1

best, Rob

another  better(?) example of expanding a function with a "Scheme Closure"


(define to-the-power
  (lambda (n)
   (lambda (x) (expt x n))))

(define square (to-the-power 2))
(define cube (to-the-power 3))

----------------------------REPL

> (square 4)
16
> (cube 4)
64
>
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 03, 2014, 12:08:26 AM
Thanks for clarification, Rob,

Your

(define-macro (inc x)
  (quasiquote (set! ,x (+ 1 ,x))))


will also do perfectly well for tinyscheme. At the moment nanoscheme would only accept macros expressed through explicit lambdas, so its syntax should be

(macro inc (lambda (x)
  `(set! ,x (+ 1 ,x))))


but it hangs -- there must still be some bug left somewhere that I've overlooked... :-[
Title: Re: Lisp in Basic
Post by: Charles Pegge on October 03, 2014, 12:34:07 AM
In my naughty LeanLisp, inc, dec and iter (down count iteration) are core functions. A function can alter the values of its own variables but no others. When it changes the value of a parameter or outside variable, it automatically makes a new local copy, masking the original.

This ensures that functional encapsulation is preserved while avoiding the strictures of functional programming.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 03, 2014, 12:53:27 AM
Hehe, frankly I don't know why Rob is so fond of hand coded iterative palliations. Scheme has legit (do) and named (let) procedures that target iterative functional programming. What else would one need? :)

Also, any such constructs reimplemented via LISP macros and/or lambdas would be slower than their core equivalents by definition.
Title: Re: Lisp in Basic
Post by: RobbeK on October 03, 2014, 01:36:32 AM
Hi Charles, Mike ,

" I don't know why Rob is so fond of hand coded iterative palliations. "         -- because I can  8)
without joking -->
Be careful,   iterations and variadic structures  do not belong together --    example :

(silent
(define sq (sequence 1 100000))
(define ar (array (length sq) sq))

(define (tst x)
 (let (( acc 0 ))
  (dotimes (i (length x))
    (++ acc (nth i x)))))

)
-------------------------------repl


> (time (tst sq))    ;; variadic container  (a list)

21640.625                    !!!!!!!!!!!!!!!!!!!!!!!!  that's 22 sec !!!!!!!!!!!!!!!!!!!!!!!!!
> > (time (tst ar))  ;; non-variadic container (vector/array)
46.875
>
---------------------------

because :  the iterative process has to start from 0 every time -- it does not remember the location of a previous pointer -  the array / vector works identical with languages as Basic, C etc ...   However, by writing the stuff myself , I do know where to locate the pointers , I do know when to set up accumulators in recursive mechanisms ,  ...  )

(define (tst L)
  (letrec (( tst* (lambda (L acc)
                 (if (null? L) acc
                    (tst* (cdr L) (+ acc (car L))))))
     (tst* L 0) )

this one goes thru the pointers as -> A -> B -> C   ...  -> NULL
the iterative form goes
-> A
-> -> B
-> -> -> C
-> -> ........................  ->NULL
 ;)

(of course C , Oxygen , Basic's etc.. can increment the pointers , but his doesn't make sense if the "pointée" is of variadic type and/or length  -- in Lisp the pointers are stored inside the data , it is not something as one memory location holding an address )

"Also, any such constructs reimplemented via LISP macros and/or lambdas would be slower than their core equivalents by definition."   -- allmost all (except the fexpressions in NewLISP) languages do the (macro)expansion while loading the code -- a compiler will do this anyway --  the expanded macro definitions are identical as coded without them, but the source is clearer to read and certainly write ....

I prefer to write something as (inc x) i.o.   (set! x (+ 1 x))  certainly if used frequently , the generated code is identical ...
(of course if already existing , rewriting same is idiotic , but I don't think Scheme has (inc ) (dec ) (++ ) (-- ) etc ..

best Rob

(ps named let is a recursive mechanism, not ??   -- I think it's based on a (letrec ...  )
furthermore , AFAIK Scheme can't even index lists , there is no (elt list index) or (nth index list)  , to avoid doing what I did at the start of this text ...

(letrec ((countdown (lambda (i)
                      (if (= i 0) 'liftoff
                          (begin
                            (display i)
                            (newline)
                            (countdown (- i 1)))))))

Title: Re: Lisp in Basic
Post by: Charles Pegge on October 03, 2014, 03:22:26 AM
For iterating over a list, (next) is a useful concept, and must be one of the fundamentals of the multiverse.

for example, a LeanLisp variadic add operation would be:

(+ (next) item )

It destructively extracts members from the list: items until it is empty.

Such an operation could be defined:

(let sum "(+ (next) item )" )

..

(sum 1 2 3 4 5)

1 2 3 4 5 is passed internally to the items variable
Title: Re: Lisp in Basic
Post by: RobbeK on October 03, 2014, 03:35:25 AM
Hi Charles, good idea to eat the pointers one by one  ;)  (in Lisp then)
   
porting it to lisp
(the non-destructive way - working on a duplicate )

(silent

(setq L (sequence 1 100000))

(constant 'next pop)    ;; pops head of a list in a destructive way  -- making just an alias ..

(define (tst x)
   (let ((tot 0) (duplicate x) )
    (dotimes (i (length x))
      (++ tot (next duplicate))) tot ))

)
------------------------------------------------------------  repl
> (time(tst L))
46.875                  -- 50 mSec : a lot better than 22 Sec.
> (length L)
100000              -- list remains intact

thanks,
best Rob

(of course Lisp as a native mechanism for above )

> (time (apply + L))
15.625

or

> (time (eval (cons + L)))
15.625
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 03, 2014, 06:15:03 AM
Hi Rob,

Your answer regarding iteration efforts stands to reason.

Macros, however, are another pair of shoes. What I really meant was that any thing expressed through user-defined macros or lambdas of a language would always be slower as compared to the same thing hardcoded in the engine of that language:

Quote
46.875                  -- 50 mSec : a lot better than 22 Sec.
(of course Lisp as a native mechanism for above )
> (time (apply + L))
15.625

That's exactly what I meant -- three times slower. :)

Quote
AFAIK Scheme can't even index lists

This isn't so. As per R5RS, Scheme has list-ref, string-ref, and vector-ref that return the respective kth elements of a list, string, or vector:

library procedure:  (list-ref list k)
Returns the kth element of list. (This is the same as the car of (list-tail list k).) It is an error if list has fewer than k elements.

(list-ref '(a b c d) 2)                         ===>  c
(list-ref '(a b c d)
          (inexact->exact (round 1.8 )))
                ===>  c
Title: Re: Lisp in Basic
Post by: RobbeK on October 03, 2014, 07:29:26 AM
Hi Mike,

(list-ref    )    ah, ok -- did not know ..   unlike CL it seems (list-set!  ) is missing ?       (setf (elt list index) something)   (common Lisp).

As mentioned above , be veeeery careful using it :           (language : Scheme)

(define a (range 1 1000000))
 
 
(define (testit x)   ;; iterative definition
   (let ((acc 0))
     (do ((i 0 (+ i 1)))
       ((= i x))
       (set! acc (+ acc (list-ref a i))))
     acc ))

(define (testrec x)        ;; TCO with a recursive helper function and accumulator
  (letrec ((test* 
            (λ (start end L acc)
              (if (= start end) acc
                  (test* (+ 1 start) end (cdr L) (+ acc (car L)))))))
    (test* 0 x a 0)   ))

---------------  REPL   switching to Scheme (not the extended Racket )


Language: scheme; memory limit: 512 MB.
> (time (testit 100000))
cpu time: 20750 real time: 20765 gc time: 0         ;;    21 sec !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5000050000

> (time (testrec 100000))
cpu time: 32 real time: 31 gc time: 0
5000050000


(bytecode with JIT compiler)


best, Rob

(as said, the (list-ref ) starts from zero over and over again when called -- the method Charles gave is much much faster -- (pop ) or (next )  if not existing is easy to write ....

(notify that apply will not work here - because I focus a subset from a list , this may be after all a raison-d'-être of both definitions, -- of which one, is to be avoided )

Addendum : this is the macro (no way I know to avoid writing a macro for this - in TinyScheme and NanoScheme (once the (macro    ) is working )

(define-macro (next L)
 (quasiquote (let (( x (car ,L)))
   (set! ,L (cdr ,L)) x )))

This definition is destructive , it changes the object L -- however, by just taking the first element, it will be very fast when used in an iterative loop ....

The (define-syntax-rule     ) is not standard Scheme   ,     sigh  ..... 
Title: Re: Lisp in Basic
Post by: RobbeK on October 06, 2014, 01:14:18 AM
Hi all,

Found some patterns in the Magic 4² squares.
Code contains a generator and evaluator ,  I first started with 3 filtering mechanisms in the generator and 7 in the evaluator.
Solving the 20922789888000 squares took about 30' -- then I found a way increasing the filters in the generator up to all 10  8)

Written/compiled in GCL  (aka Austin Kyoto Common Lisp)

compiler output :
";; Note: Tail-recursive call of REMOVE* was replaced by iteration."   (the recursive list on list filter - the heart of the code)

Main calculating loop contains a listener, you can close the program at any time.
Use the batch file to run the program ,  Mike's JavaKiller comes with it , it will kill the unneeded javaw.exe on exit.

best Rob (took me a few hours to find the pattern - but it came suddenly  - it's based on a St-Andrew's cross  ;)
enjoy the speed
(you probably will have to "un 7zip" it on your disk before the batch file will find the executables )


.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 06, 2014, 12:01:55 PM
Thanks Rob,

Your program works very smoothly and does 7040 squares in exactly 33 seconds on my PC. Your tiny oxyblaster also does its merciless work flawlessly. (you could've compiled it completely standalone too btw)

:)
Title: Re: Lisp in Basic
Post by: RobbeK on October 10, 2014, 01:13:22 PM
Hi Mike,

thanks,   those number patterns are much more difficult to code than fractals -- sadly, less spectacular  :(

Started studying more deeply Haskell,  -- another λ language  .. rather fascinating :
no iteration at all
completely "profound" lazy   (i think i found a soulmate  8)   )
but, very compact ...    translated a few things from Lisp / Scheme :

the single recursive fibo

fibo (a,b,0) = a
fibo (a,b,i)= fibo(b,a+b,i-1)

fib (x) = fibo(1,1,x)

----------------------------------------

working with lists it splits the list in the car and cdr as (x:xs)  --- list defined by using brackets

fact [1] = 1
fact (x:xs) = x*fact(xs)

----------------------------------------

defining mapping is very easy :  (named mmap, it already has map of course)

mmap f [] = []
mmap f (x:xs) = f x : mmap f xs

in the REPL

*Main> mmap (/ 2) [1..5]
[0.5,1.0,1.5,2.0,2.5]

well, interesting ...

consing is done by   ":"   p.e. 0 : [1,2]        -> [0,1,2]           (same as (cons 0 (list 1 2))         )


best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 10, 2014, 02:08:46 PM
Rob,

Have you ever tried Brainf*ck, I wonder? :D
Title: Re: Lisp in Basic
Post by: RobbeK on October 11, 2014, 12:44:47 AM
Hi Mike,


Brainf*ck  ...    wikipedia says it's Turing complete  ;)


http://www.turtle.dds.nl/nothing/              (somewhat dadaistic )

best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 11, 2014, 09:14:14 AM
Yes Rob,

It is absolutely brainf*cking but it is Turing complete. Every decent language must have a BF interpreter of its own implemented for the amusement of its most inquisitive users. I have three of them, the best one being written in C -- damn, it has its own full-blown IDE! :D

And it is damned fast too.

Once upon a time when we all weren't yet acquainted with each other, John launched an ASCII Mandelbrot challenge on one of his innumerous sites based off of BF algorithm of doing same as a specimen to follow.

Naturally enough PowerBASIC was the fastest among the compilers. Charles was a close second with his Oxygen but he used a couple of dirty tricks to optimize the algo while nobody noticed. (If I had been among the contestants, I would have had him withdrawn from the race mercilessly! :D )

BASIC interpreters were doing very, very badly being some 5 to 10 times slower than BF. I must still have some snapshots somewhere on my disks that I took watching the show from aside with my bucket of popcorn in hand. :)

I'm still using this code as a regression test for my FBSL builds.

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 11, 2014, 10:54:42 AM
Quote from: Rob
http://www.turtle.dds.nl/nothing/

A-a-a-ha-ha-ha-ha-ha-ha-ha-ha!!!!!

You made my day, Rob! ;D

See Equality: A Feministic Programming Language (sorry but the original site is already down :D )

.
Title: Re: Lisp in Basic
Post by: Charles Pegge on October 11, 2014, 11:44:58 AM
Sounds like a dialectic of Marxist Programming Language :)

In contrast, to Monarchical programming languages, require a strict class hierarchy, and creates subjects instead of objects. Subjects participate in ceremonies instead of procedures, and return tributes. When subjects no longer participate in ceremonies, they are exiled to the heap, but occasionally, they are executed.
Title: Re: Lisp in Basic
Post by: JRS on October 11, 2014, 11:50:02 AM
Quote from: Charles
In contrast, to Monarchical programming languages, require a strict class hierarchy, and creates subjects instead of objects. Subjects participate in ceremonies instead of procedures, and return tributes. When subjects no longer participate in ceremonies, they are exiled to the heap, but occasionally, they are executed.

A good definition of encapsulation.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 11, 2014, 11:54:52 AM
Pardon my poor English, guys, do you mean "they are executed" -- by an executioner?
Title: Re: Lisp in Basic
Post by: Charles Pegge on October 11, 2014, 12:11:37 PM
Yes, when the monarch takes exception, they are decapsulated. In other words, their headers are detached.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 11, 2014, 12:17:56 PM
Or they are detached from their headers, ha-ha-ha-ha-ha!!!!

Thanks, Charles, for this refreshing and reassuring insight from a loyal patrial of British Empire!  ;D
Title: Re: Lisp in Basic
Post by: RobbeK on October 12, 2014, 07:45:50 AM
Hi all,

"dirty tricks to optimize"  ...   sounds interesting, how can one ...  ??   pre-memoized tables somewhere ..  ?

BF :  rather a "tour de force" to generate such code from the keyboard ?

 ...   they are executed.   ::)   , or they keep hanging ?

best, Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 12, 2014, 06:24:13 PM
My annals are keeping it all safe, Rob. Code submissions, benchmarks published, site correspondence, screenshots -- everything that I ever happened to be interested in or stricken by. You may call it paranoia but that's the way I've always been, prepared to stand up to every single word I say every single moment of my life. I was born in the KGB hell, you know, and hell is where I still keep on living somehow. :)

Never mind though.

Tour de force? Judge for yourself: ;)

Code: [Select]
+++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[
>>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+
<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>>
>+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>>
>>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>>
>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>>
>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>
[>>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<
<<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]>>>>>>>>>+++++++++++++++[[
>>>>>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[
>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->>[
-<<+>>]<<[->>+>>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<
<<[>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<
[>[-]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+<<<<<<<<<]>>>>>
>>>>[>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+
<<<<<<[->>>[-<<<+>>>]<<<[->>>+>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>
>>>>>>>]<<<<<<<<<[>>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<<]>>[->>>>>>>>>+<<<<<<<<<]<<
+>>>>>>>>]<<<<<<<<<[>[-]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<
<]<+<<<<<<<<<]>>>>>>>>>[>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>
>>>>>]<<<<<<<<<-<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+>>>>>>>>>>>>>>>>>>>>>+<<<[<<<<<<
<<<]>>>>>>>>>[>>>[-<<<->>>]+<<<[->>>->[-<<<<+>>>>]<<<<[->>>>+<<<<<<<<<<<<<[<<<<<
<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>[-<<<<->>>>]+<<<<[->>>>-<[-<<<+>>>]<<<[->
>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<
<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]<<<<<<<[->+>>>-<<<<]>>>>>>>>>+++++++++++++++++++
+++++++>>[-<<<<+>>>>]<<<<[->>>>+<<[-]<<]>>[<<<<<<<+<[-<+>>>>+<<[-]]>[-<<[->+>>>-
<<<<]>>>]>>>>>>>>>>>>>[>>[-]>[-]>[-]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-]>>>>>>[>>>>>
[-<<<<+>>>>]<<<<[->>>>+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>[-<<<<<<<<
<+>>>>>>>>>]>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>>>>>>]+>[-
]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[>+>>>>>>>>]<<<
<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<<<[->>[-<<+>>]<
<[->>+>+<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>[->>>>
>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[>[-]<->>>
[-<<<+>[<->-<<<<<<<+>>>>>>>]<[->+<]>>>]<<[->>+<<]<+<<<<<<<<<]>>>>>>>>>[>>>>>>[-<
<<<<+>>>>>]<<<<<[->>>>>+<<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>+>>>>>>>>
]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<<<[->>[-<<+
>>]<<[->>+>>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>
[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[>[-
]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+<<<<<<<<<]>>>>>>>>>
[>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>++++++++
+++++++[[>>>>>>>>>]<<<<<<<<<-<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-<<<<<<<+
>>>>>>>]<<<<<<<[->>>>>>>+<<<<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[
-]>>>]<<<<<<<<<[<<<<<<<<<]>>>>+>[-<-<<<<+>>>>>]>[-<<<<<<[->>>>>+<++<<<<]>>>>>[-<
<<<<+>>>>>]<->+>]<[->+<]<<<<<[->>>>>+<<<<<]>>>>>>[-]<<<<<<+>>>>[-<<<<->>>>]+<<<<
[->>>>->>>>>[>>[-<<->>]+<<[->>->[-<<<+>>>]<<<[->>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]
+>>>>>>[>>>>>>>>>]>+<]]+>>>[-<<<->>>]+<<<[->>>-<[-<<+>>]<<[->>+<<<<<<<<<<<[<<<<<
<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<
[<<<<<<<<<]>>>>[-<<<<+>>>>]<<<<[->>>>+>>>>>[>+>>[-<<->>]<<[->>+<<]>>>>>>>>]<<<<<
<<<+<[>[->>>>>+<<<<[->>>>-<<<<<<<<<<<<<<+>>>>>>>>>>>[->>>+<<<]<]>[->>>-<<<<<<<<<
<<<<<+>>>>>>>>>>>]<<]>[->>>>+<<<[->>>-<<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>>+<<<]<<
<<<<<<<<<<]>>>>[-]<<<<]>>>[-<<<+>>>]<<<[->>>+>>>>>>[>+>[-<->]<[->+<]>>>>>>>>]<<<
<<<<<+<[>[->>>>>+<<<[->>>-<<<<<<<<<<<<<<+>>>>>>>>>>[->>>>+<<<<]>]<[->>>>-<<<<<<<
<<<<<<<+>>>>>>>>>>]<]>>[->>>+<<<<[->>>>-<<<<<<<<<<<<<<+>>>>>>>>>>]>]<[->>>>+<<<<
]<<<<<<<<<<<]>>>>>>+<<<<<<]]>>>>[-<<<<+>>>>]<<<<[->>>>+>>>>>[>>>>>>>>>]<<<<<<<<<
[>[->>>>>+<<<<[->>>>-<<<<<<<<<<<<<<+>>>>>>>>>>>[->>>+<<<]<]>[->>>-<<<<<<<<<<<<<<
+>>>>>>>>>>>]<<]>[->>>>+<<<[->>>-<<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>>+<<<]<<<<<<<
<<<<<]]>[-]>>[-]>[-]>>>>>[>>[-]>[-]>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>[-<
<<<+>>>>]<<<<[->>>>+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[
[>>>>>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+
[>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->>
[-<<+>>]<<[->>+>+<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<
<[>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[
>[-]<->>>[-<<<+>[<->-<<<<<<<+>>>>>>>]<[->+<]>>>]<<[->>+<<]<+<<<<<<<<<]>>>>>>>>>[
>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]>
>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>[-]>>>>+++++++++++++++[[>>>>>>>>>]<<<<<<<<<-<<<<<
<<<<[<<<<<<<<<]>>>>>>>>>-]+[>>>[-<<<->>>]+<<<[->>>->[-<<<<+>>>>]<<<<[->>>>+<<<<<
<<<<<<<<[<<<<<<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>[-<<<<->>>>]+<<<<[->>>>-<[-
<<<+>>>]<<<[->>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>
>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-<<<+>>>]<<<[->>>+>>>>>>[>+>>>
[-<<<->>>]<<<[->>>+<<<]>>>>>>>>]<<<<<<<<+<[>[->+>[-<-<<<<<<<<<<+>>>>>>>>>>>>[-<<
+>>]<]>[-<<-<<<<<<<<<<+>>>>>>>>>>>>]<<<]>>[-<+>>[-<<-<<<<<<<<<<+>>>>>>>>>>>>]<]>
[-<<+>>]<<<<<<<<<<<<<]]>>>>[-<<<<+>>>>]<<<<[->>>>+>>>>>[>+>>[-<<->>]<<[->>+<<]>>
>>>>>>]<<<<<<<<+<[>[->+>>[-<<-<<<<<<<<<<+>>>>>>>>>>>[-<+>]>]<[-<-<<<<<<<<<<+>>>>
>>>>>>>]<<]>>>[-<<+>[-<-<<<<<<<<<<+>>>>>>>>>>>]>]<[-<+>]<<<<<<<<<<<<]>>>>>+<<<<<
]>>>>>>>>>[>>>[-]>[-]>[-]>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-]>[-]>>>>>[>>>>>>>[-<<<<<
<+>>>>>>]<<<<<<[->>>>>>+<<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>+>[-<-<<<<+>>>>
>]>>[-<<<<<<<[->>>>>+<++<<<<]>>>>>[-<<<<<+>>>>>]<->+>>]<<[->>+<<]<<<<<[->>>>>+<<
<<<]+>>>>[-<<<<->>>>]+<<<<[->>>>->>>>>[>>>[-<<<->>>]+<<<[->>>-<[-<<+>>]<<[->>+<<
<<<<<<<<<[<<<<<<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>[-<<->>]+<<[->>->[-<<<+>>>]<
<<[->>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<
<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-<<<+>>>]<<<[->>>+>>>>>>[>+>[-<->]<[->+
<]>>>>>>>>]<<<<<<<<+<[>[->>>>+<<[->>-<<<<<<<<<<<<<+>>>>>>>>>>[->>>+<<<]>]<[->>>-
<<<<<<<<<<<<<+>>>>>>>>>>]<]>>[->>+<<<[->>>-<<<<<<<<<<<<<+>>>>>>>>>>]>]<[->>>+<<<
]<<<<<<<<<<<]>>>>>[-]>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]]>>>>[-<<<<+>
>>>]<<<<[->>>>+>>>>>[>+>>[-<<->>]<<[->>+<<]>>>>>>>>]<<<<<<<<+<[>[->>>>+<<<[->>>-
<<<<<<<<<<<<<+>>>>>>>>>>>[->>+<<]<]>[->>-<<<<<<<<<<<<<+>>>>>>>>>>>]<<]>[->>>+<<[
->>-<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>+<<]<<<<<<<<<<<<]]>>>>[-]<<<<]>>>>[-<<<<+>>
>>]<<<<[->>>>+>[-]>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]>>>>>>>>>[>>>>>>
>>>]<<<<<<<<<[>[->>>>+<<<[->>>-<<<<<<<<<<<<<+>>>>>>>>>>>[->>+<<]<]>[->>-<<<<<<<<
<<<<<+>>>>>>>>>>>]<<]>[->>>+<<[->>-<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>+<<]<<<<<<<<
<<<<]]>>>>>>>>>[>>[-]>[-]>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-]>[-]>>>>>[>>>>>[-<<<<+
>>>>]<<<<[->>>>+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<+>>>>>
]<<<<<[->>>>>+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>
>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[>+>>
>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->>[-<<+
>>]<<[->>+>>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>
[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[>[-
]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+<<<<<<<<<]>>>>>>>>>
[>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<
<<[->>>[-<<<+>>>]<<<[->>>+>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>
>>>]<<<<<<<<<[>>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<<]>>[->>>>>>>>>+<<<<<<<<<]<<+>>>
>>>>>]<<<<<<<<<[>[-]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+
<<<<<<<<<]>>>>>>>>>[>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>>>>>
>]<<<<<<<<<-<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+>>>>>>>>>>>>>>>>>>>>>+<<<[<<<<<<<<<]
>>>>>>>>>[>>>[-<<<->>>]+<<<[->>>->[-<<<<+>>>>]<<<<[->>>>+<<<<<<<<<<<<<[<<<<<<<<<
]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>[-<<<<->>>>]+<<<<[->>>>-<[-<<<+>>>]<<<[->>>+<
<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>
>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>->>[-<<<<+>>>>]<<<<[->>>>+<<[-]<<]>>]<<+>>>>[-<<<<
->>>>]+<<<<[->>>>-<<<<<<.>>]>>>>[-<<<<<<<.>>>>>>>]<<<[-]>[-]>[-]>[-]>[-]>[-]>>>[
>[-]>[-]>[-]>[-]>[-]>[-]>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>[-]>>>>]<<<<<<<<<
[<<<<<<<<<]>+++++++++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>+>>>>>>>>>+<<<<<<<<
<<<<<<[<<<<<<<<<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+[-]>>[>>>>>>>>>]<<<<<
<<<<[>>>>>>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<[<<<<<<<<<]>>>>>>>[-]+>>>]<<<<
<<<<<<]]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+>>[>+>>>>[-<<<<->>>>]<<<<[->>>
>+<<<<]>>>>>>>>]<<+<<<<<<<[>>>>>[->>+<<]<<<<<<<<<<<<<<]>>>>>>>>>[>>>>>>>>>]<<<<<
<<<<[>[-]<->>>>>>>[-<<<<<<<+>[<->-<<<+>>>]<[->+<]>>>>>>>]<<<<<<[->>>>>>+<<<<<<]<
+<<<<<<<<<]>>>>>>>-<<<<[-]+<<<]+>>>>>>>[-<<<<<<<->>>>>>>]+<<<<<<<[->>>>>>>->>[>>
>>>[->>+<<]>>>>]<<<<<<<<<[>[-]<->>>>>>>[-<<<<<<<+>[<->-<<<+>>>]<[->+<]>>>>>>>]<<
<<<<[->>>>>>+<<<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>+<<<
<<[<<<<<<<<<]>>>>>>>>>[>>>>>[-<<<<<->>>>>]+<<<<<[->>>>>->>[-<<<<<<<+>>>>>>>]<<<<
<<<[->>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>[-<
<<<<<<->>>>>>>]+<<<<<<<[->>>>>>>-<<[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<<<<<<<<<<<[<<<
<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<
<<[<<<<<<<<<]>>>>[-]<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>-<<<<<[<<<<<<<
<<]]>>>]<<<<.>>>>>>>>>>[>>>>>>[-]>>>]<<<<<<<<<[<<<<<<<<<]>++++++++++[-[->>>>>>>>
>+<<<<<<<<<]>>>>>>>>>]>>>>>+>>>>>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-<<<<<<
<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+[-]>[>>>>>>>>>]<<<<<<<<<[>>>>>>>>[-<<<<<<<+>>>>>>
>]<<<<<<<[->>>>>>>+<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+>>]<<<<<<<<<<]]>>>>>>>>[-<<<<<
<<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+>[>+>>>>>[-<<<<<->>>>>]<<<<<[->>>>>+<<<<<]>>>>>>
>>]<+<<<<<<<<[>>>>>>[->>+<<]<<<<<<<<<<<<<<<]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>[-]<-
>>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<<<<<<<[->>>>>>>+<<<<<<<]<+<<<<<<
<<<]>>>>>>>>-<<<<<[-]+<<<]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>->[>>>
>>>[->>+<<]>>>]<<<<<<<<<[>[-]<->>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<<
<<<<<[->>>>>>>+<<<<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>
+>>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<<->>>>>>]+<
<<<<<[->>>>>>->>[-<<<<<<<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+<<<<<<<<<<<<<<<<<[<<<<<<<
<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>
-<<[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>
>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++
+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<
<<<<<]]>>>]

It takes less than 60 seconds to complete in the BF IDE but it takes over 5.5 minutes to do the same via John's ScriptBASIC -- on my PC.

(" ...   they are executed.   ::)   , or they keep hanging ?" -- Monsieur sait beaucoup sur la perversion? :D )
Title: Re: Lisp in Basic
Post by: JRS on October 12, 2014, 07:03:13 PM
Here is the time using my BF2SB converter.

Code: Script BASIC
  1. bfname = COMMAND()
  2. bfsize = FILELEN(bfname)
  3. OPEN bfname FOR INPUT AS #1
  4. bfpgm = INPUT(bfsize, #1)
  5. pgm = Strip(bfpgm)
  6. pgmsize = LEN(pgm)
  7. dot = INSTR(bfname,".")
  8. sbname = LEFT(bfname, dot) & "sb"
  9. OPEN sbname FOR OUTPUT AS #2
  10. PRINT #2, "SPLITA STRING(30000,48) BY \"\" TO memory\n"
  11. cellptr = 0
  12. cmdptr = 1
  13. indent = ""
  14.  
  15. Next_Cmd:
  16.  
  17. cmd = MID(pgm, cmdptr, 1)
  18. IF cmd = ">" THEN
  19.   CALL Group
  20.   PRINT #2, indent & "cellptr += " & x & "\n"
  21. END IF
  22. IF cmd = "<" THEN
  23.   CALL Group
  24.   PRINT #2, indent & "cellptr -= " & x & "\n"
  25. END IF
  26. IF cmd = "+" THEN
  27.   CALL Group
  28.   PRINT #2, indent & "memory[cellptr] += " & x & "\n"
  29. END IF
  30. IF cmd = "-" THEN
  31.   CALL Group
  32.   PRINT #2, indent & "memory[cellptr] -= " & x & "\n"
  33. END IF
  34. IF cmd = "." THEN
  35.   PRINT #2, indent & "IF memory[cellptr] = 10 THEN\n"
  36.   indent &= STRING(2," ")
  37.   PRINT #2, indent & "PRINTNL\n"
  38.   indent = LEFT(indent, LEN(indent) - 2)
  39.   PRINT #2, indent & "ELSE\n"
  40.   indent &= STRING(2," ")
  41.   PRINT #2, indent & "PRINT CHR(memory[cellptr])\n"
  42.   indent = LEFT(indent, LEN(indent) - 2)
  43.   PRINT #2, indent & "END IF\n"
  44. END IF
  45. IF cmd = "," THEN PRINT #2, indent & "memory[cellptr] = ASC(INPUT(1))\n"
  46. IF cmd = "[" THEN
  47.   PRINT #2, indent & "WHILE memory[cellptr] > 0\n"
  48.   indent &= STRING(2," ")
  49. END IF
  50. IF cmd = "]" THEN
  51.   IF LEN(indent) > 2 THEN
  52.     indent = LEFT(indent, LEN(indent) - 2)
  53.   ELSE
  54.     indent = ""
  55.   END IF
  56.   PRINT #2, indent & "WEND\n"
  57. END IF
  58. IF cmdptr + 1 > pgmsize THEN
  59.   GOTO Bye
  60. ELSE
  61.   cmdptr += 1
  62.   GOTO Next_Cmd
  63. END IF
  64.  
  65. Bye:
  66. END
  67.  
  68. FUNCTION Strip(codein)
  69.   LOCAL codein,codeout,bfcmd, i
  70.   codeout = ""
  71.   FOR i = 1 TO bfsize
  72.     bfcmd = MID(codein, i, 1)
  73.     IF INSTR("><+-.,[]", bfcmd) THEN codeout &= bfcmd
  74.   NEXT i
  75.   Strip = codeout
  76. END FUNCTION
  77.  
  78. SUB Group
  79.   x = 0
  80.   WHILE MID(pgm, cmdptr + x, 1) = cmd
  81.     x += 1
  82.   WEND
  83.   cmdptr += x - 1
  84. END SUB  
  85.  

Code: [Select]
jrs@laptop:~/sb/sb22/bf$ time scriba tdef.sb
AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDEGFFEEEEDDDDDDCCCCCCCCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
AAAAAAAAAAAAAAABBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDEEEFGIIGFFEEEDDDDDDDDCCCCCCCCCBBBBBBBBBBBBBBBBBBBBBBBBBB
AAAAAAAAAAAAABBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDEEEEFFFI KHGGGHGEDDDDDDDDDCCCCCCCCCBBBBBBBBBBBBBBBBBBBBBBB
AAAAAAAAAAAABBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDEEEEEFFGHIMTKLZOGFEEDDDDDDDDDCCCCCCCCCBBBBBBBBBBBBBBBBBBBBB
AAAAAAAAAAABBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDEEEEEEFGGHHIKPPKIHGFFEEEDDDDDDDDDCCCCCCCCCCBBBBBBBBBBBBBBBBBB
AAAAAAAAAABBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDEEEEEEFFGHIJKS  X KHHGFEEEEEDDDDDDDDDCCCCCCCCCCBBBBBBBBBBBBBBBB
AAAAAAAAABBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDEEEEEEFFGQPUVOTY   ZQL[MHFEEEEEEEDDDDDDDCCCCCCCCCCCBBBBBBBBBBBBBB
AAAAAAAABBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDEEEEEFFFFFGGHJLZ         UKHGFFEEEEEEEEDDDDDCCCCCCCCCCCCBBBBBBBBBBBB
AAAAAAABBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDEEEEFFFFFFGGGGHIKP           KHHGGFFFFEEEEEEDDDDDCCCCCCCCCCCBBBBBBBBBBB
AAAAAAABBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDEEEEEFGGHIIHHHHHIIIJKMR        VMKJIHHHGFFFFFFGSGEDDDDCCCCCCCCCCCCBBBBBBBBB
AAAAAABBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDEEEEEEFFGHK   MKJIJO  N R  X      YUSR PLV LHHHGGHIOJGFEDDDCCCCCCCCCCCCBBBBBBBB
AAAAABBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDEEEEEEEEEFFFFGH O    TN S                       NKJKR LLQMNHEEDDDCCCCCCCCCCCCBBBBBBB
AAAAABBCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDEEEEEEEEEEEEFFFFFGHHIN                                 Q     UMWGEEEDDDCCCCCCCCCCCCBBBBBB
AAAABBCCCCCCCCCCCCCCCCCCCCCCCCCDDDDEEEEEEEEEEEEEEEFFFFFFGHIJKLOT                                     [JGFFEEEDDCCCCCCCCCCCCCBBBBB
AAAABCCCCCCCCCCCCCCCCCCCCCCDDDDEEEEEEEEEEEEEEEEFFFFFFGGHYV RQU                                     QMJHGGFEEEDDDCCCCCCCCCCCCCBBBB
AAABCCCCCCCCCCCCCCCCCDDDDDDDEEFJIHFFFFFFFFFFFFFFGGGGGGHIJN                                            JHHGFEEDDDDCCCCCCCCCCCCCBBB
AAABCCCCCCCCCCCDDDDDDDDDDEEEEFFHLKHHGGGGHHMJHGGGGGGHHHIKRR                                           UQ L HFEDDDDCCCCCCCCCCCCCCBB
AABCCCCCCCCDDDDDDDDDDDEEEEEEFFFHKQMRKNJIJLVS JJKIIIIIIJLR                                               YNHFEDDDDDCCCCCCCCCCCCCBB
AABCCCCCDDDDDDDDDDDDEEEEEEEFFGGHIJKOU  O O   PR LLJJJKL                                                OIHFFEDDDDDCCCCCCCCCCCCCCB
AACCCDDDDDDDDDDDDDEEEEEEEEEFGGGHIJMR              RMLMN                                                 NTFEEDDDDDDCCCCCCCCCCCCCB
AACCDDDDDDDDDDDDEEEEEEEEEFGGGHHKONSZ                QPR                                                NJGFEEDDDDDDCCCCCCCCCCCCCC
ABCDDDDDDDDDDDEEEEEFFFFFGIPJIIJKMQ                   VX                                                 HFFEEDDDDDDCCCCCCCCCCCCCC
ACDDDDDDDDDDEFFFFFFFGGGGHIKZOOPPS                                                                      HGFEEEDDDDDDCCCCCCCCCCCCCC
ADEEEEFFFGHIGGGGGGHHHHIJJLNY                                                                        TJHGFFEEEDDDDDDDCCCCCCCCCCCCC
A                                                                                                 PLJHGGFFEEEDDDDDDDCCCCCCCCCCCCC
ADEEEEFFFGHIGGGGGGHHHHIJJLNY                                                                        TJHGFFEEEDDDDDDDCCCCCCCCCCCCC
ACDDDDDDDDDDEFFFFFFFGGGGHIKZOOPPS                                                                      HGFEEEDDDDDDCCCCCCCCCCCCCC
ABCDDDDDDDDDDDEEEEEFFFFFGIPJIIJKMQ                   VX                                                 HFFEEDDDDDDCCCCCCCCCCCCCC
AACCDDDDDDDDDDDDEEEEEEEEEFGGGHHKONSZ                QPR                                                NJGFEEDDDDDDCCCCCCCCCCCCCC
AACCCDDDDDDDDDDDDDEEEEEEEEEFGGGHIJMR              RMLMN                                                 NTFEEDDDDDDCCCCCCCCCCCCCB
AABCCCCCDDDDDDDDDDDDEEEEEEEFFGGHIJKOU  O O   PR LLJJJKL                                                OIHFFEDDDDDCCCCCCCCCCCCCCB
AABCCCCCCCCDDDDDDDDDDDEEEEEEFFFHKQMRKNJIJLVS JJKIIIIIIJLR                                               YNHFEDDDDDCCCCCCCCCCCCCBB
AAABCCCCCCCCCCCDDDDDDDDDDEEEEFFHLKHHGGGGHHMJHGGGGGGHHHIKRR                                           UQ L HFEDDDDCCCCCCCCCCCCCCBB
AAABCCCCCCCCCCCCCCCCCDDDDDDDEEFJIHFFFFFFFFFFFFFFGGGGGGHIJN                                            JHHGFEEDDDDCCCCCCCCCCCCCBBB
AAAABCCCCCCCCCCCCCCCCCCCCCCDDDDEEEEEEEEEEEEEEEEFFFFFFGGHYV RQU                                     QMJHGGFEEEDDDCCCCCCCCCCCCCBBBB
AAAABBCCCCCCCCCCCCCCCCCCCCCCCCCDDDDEEEEEEEEEEEEEEEFFFFFFGHIJKLOT                                     [JGFFEEEDDCCCCCCCCCCCCCBBBBB
AAAAABBCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDEEEEEEEEEEEEFFFFFGHHIN                                 Q     UMWGEEEDDDCCCCCCCCCCCCBBBBBB
AAAAABBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDEEEEEEEEEFFFFGH O    TN S                       NKJKR LLQMNHEEDDDCCCCCCCCCCCCBBBBBBB
AAAAAABBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDEEEEEEFFGHK   MKJIJO  N R  X      YUSR PLV LHHHGGHIOJGFEDDDCCCCCCCCCCCCBBBBBBBB
AAAAAAABBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDEEEEEFGGHIIHHHHHIIIJKMR        VMKJIHHHGFFFFFFGSGEDDDDCCCCCCCCCCCCBBBBBBBBB
AAAAAAABBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDEEEEFFFFFFGGGGHIKP           KHHGGFFFFEEEEEEDDDDDCCCCCCCCCCCBBBBBBBBBBB
AAAAAAAABBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDEEEEEFFFFFGGHJLZ         UKHGFFEEEEEEEEDDDDDCCCCCCCCCCCCBBBBBBBBBBBB
AAAAAAAAABBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDEEEEEEFFGQPUVOTY   ZQL[MHFEEEEEEEDDDDDDDCCCCCCCCCCCBBBBBBBBBBBBBB
AAAAAAAAAABBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDEEEEEEFFGHIJKS  X KHHGFEEEEEDDDDDDDDDCCCCCCCCCCBBBBBBBBBBBBBBBB
AAAAAAAAAAABBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDEEEEEEFGGHHIKPPKIHGFFEEEDDDDDDDDDCCCCCCCCCCBBBBBBBBBBBBBBBBBB
AAAAAAAAAAAABBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDEEEEEFFGHIMTKLZOGFEEDDDDDDDDDCCCCCCCCCBBBBBBBBBBBBBBBBBBBBB
AAAAAAAAAAAAABBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDEEEEFFFI KHGGGHGEDDDDDDDDDCCCCCCCCCBBBBBBBBBBBBBBBBBBBBBBB
AAAAAAAAAAAAAAABBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDEEEFGIIGFFEEEDDDDDDDDCCCCCCCCCBBBBBBBBBBBBBBBBBBBBBBBBBB

real 8m34.051s
user 8m33.587s
sys 0m0.036s
jrs@laptop:~/sb/sb22/bf$

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 12, 2014, 08:06:23 PM
See my current screenshots below. Timings taken with a Windows scriba.exe dated 01/28/2005 available at the time of the challenge.

Many of your comparison methods and conclusions could in fact have been questioned at that time but somehow weren't. Why? I don't know, really. :)

Attached is also your original script with my launcher that would allow you to adjust the size of Windows console at its first "Press any key to continue..." pause to a width of 132 chars that ensures a coherent picture of the app output. Just unzip scriba.exe from its original zip into the same folder and double click RunTimedMandel.exe.

BF IDE is also included. Unzip it anywhere you like and enjoy. I can supply a few other BF scripts if needed.

Original BCX, OxygenBasic, thinBasic, FreeBASIC, PowerBASIC, and FBSL scripts and exes are available on demand. Free of charge, of course. As in "free beer". :D

.
Title: Re: Lisp in Basic
Post by: JRS on October 12, 2014, 08:16:48 PM
Please use the tdef.sb version or use the converter on your BF code. I optimized the original converter which seem to help.

Mandelbrot BF Facts:

686 nested WHILE/WEND loops (SB translated)
10,521,107,970 instructions (.bf interpreted)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 12, 2014, 08:20:38 PM
Doesn't help you any against the BF IDE tho. :D
Title: Re: Lisp in Basic
Post by: JRS on October 12, 2014, 08:25:56 PM
The converter was meant to make the BF interpreter faster in SB. I will try to dig up the original SB .bf file interpreter.

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 12, 2014, 08:30:13 PM
Please DO NOT bother. It will be an interpreter within an interpreter. You already know by SBLisp what it means. Use BF IDE to have a BF interpreter that is powered by C compiled to machine code the same way as your SB or my FBSL are, and therefore compatible with them in its true speed.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 12, 2014, 08:33:42 PM
Sorry gents, the RunTimedMandel launcher I posted has my PC filepaths hardcoded in the original script. It won't run for you on your PC's.

Please use the one from the attached zip.

.
Title: Re: Lisp in Basic
Post by: JRS on October 12, 2014, 08:37:58 PM
Quote
That was the first one of your obvious shoot-and-misses way back then, John.

Hey Mike,

Take a break and chill out. You're starting to sound like Aurel.  ???
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on October 12, 2014, 08:42:12 PM
Sorry John, it wasn't my intention. My English must be slipping me this 7:40 Monday morning with 2 bottles of porto behind. (Offending line deleted)
Title: Re: Lisp in Basic
Post by: RobbeK on October 24, 2014, 08:35:52 AM
Hi Mike, (all)

Still working on your Scheme ??

...  coded the Brownian motion in Lisp , it's nice to see it only takes 3 lines of code  8)   -- variadic, any size of area, any number of particles ....
added something --  frames give : the particles -- the history (trajects of the particles) and a simulation of objects moved by those particles ,,,,      interpreted newLISP , non-buffered graphics ..

the core =

(define (mutate L M)
 (if (null? L) M
   (mutate (rest L) (cons (map (curry + (-- (rand 3))) (first L)) M))))               ;;;  (everything is calculated here )


best, Rob

(use the batch file, it will remove the hanging javaw.exe task)  -- to close the main window, first use stop / start ...

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on November 01, 2014, 08:47:38 PM
Hi Rob,

Sorry for being late with my answer; I somehow missed your message here.

Thanks for this spectacular boiling kettle -- looks very viral. :)

Yes, I'm still working on porting nanoscheme to O2 in my spare time. I did about 1,300 lines which is roughly half of the file. The original C code works faultlessly in my FBSL DynC if only a trifle slower than when statically compiled with GCC. I think the resultant O2 equivalent will be as fast as the original. I'll revive this thread when I'm through with porting. Stay tuned! :)
Title: Re: Lisp in Basic
Post by: RobbeK on November 07, 2014, 04:50:12 AM
Thanks Mike,

(rather busy on a job now )


best Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on November 09, 2014, 12:37:20 AM
Hi Rob,

Sorry to keep you waiting but O2 pointers and casts are so, uhm, unusual that debugging string operations while trying to keep the sources more or less C style is going to take considerable time. So far I've debugged nanoscheme initialization only and am stuck with reading in the init.scm file. Still a long way to go till I can see the ">" prompt on my screen. :)
Title: Re: Lisp in Basic -- Lisp and BASIC
Post by: RobbeK on January 05, 2015, 01:53:43 PM
Hi all,

GFA + NewLISP  -- works very well imho  ---      let it snow :
3 layers of stars?/flakes? with their own size and brownian motion up/down/left/right
Using the GFA GDI connection, but can be a lot faster when using bitmaps (shared bitmaps between lisp and gfa are possible - already tested).
Now I can use the Timers from GFA (those from NewLISP only work in Linux (idem for semaphores and some other things).

Why the Lisp is used : because it's much much simpler to write such code -  i do not have to care about numbers of stars/flakes - size of the grid - I just map a brownian motion and the gravity effect on a variadic list.   -- when a particle reaches "ground zero" it starts again from the top.
Lisp code is included as "REM's" , but I already set up an editor from within GFA

Well, finally  :D  i"m getting somewhere ..

NewLISP is not a compiler , it does not have the full numeric tower (but bignumbers) -- but it is a great tool and capable of macro's ....

(ah, it has callback functions too and an excellent FFI )

best Rob   (i named the lisp files to feed GFA  *.lxp)  -- no screen cap / could not catch them (they are in a timer cycle)



.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on January 05, 2015, 11:04:34 PM
Hi Rob,

I'm glad you're finally coming closer to the toolchain that can meet your specs.

Just wanted to note that:
Exclusively for your reference, please have a look at how FBSL's pure interpreted BASIC (not a single JIT C or asm line in the entire project) would deal with 500 snowflake sprites that keep on falling while the game remains totally responsive to the user interaction with other animated objects in the scene -- the Xmas tree and roof lights, home owner, and bouncing snowman. And all this in a single thread of execution with 6 simultaneously mixable channels of non-DirectAudio .MID and .MP3 music and sounds! :)

The maximum number of snowflake sprites that would still let the game keep on running interactively is nine thousand discrete visible pieces. That many would however prevent me from recording smoothly the .AVI attached below.

Please note that you'll be able to watch the .AVI only if you have an Xvid MPEG4 codec installed on your PC. If not, you should find one on the net and install it. It yields the smoothest, fastest and tiniest high-quality bitstreams for streaming video recording and playback.

(http://www.fbsl.net/phpbb2/download/file.php?id=1916)


You can download the zip with the .AVI file here (http://www.fbsl.net/phpbb2/download/file.php?id=1917).

Title: Re: Lisp in Basic
Post by: JRS on January 05, 2015, 11:29:41 PM
That is a Charles thing and I only deal with hosting issues. This is not my site or forum. My hosting and direct support to Charles is my contribution to the OxygenBasic project. Other than that, I'm just a user here like everyone else.

Title: Re: Lisp in Basic
Post by: JRS on January 05, 2015, 11:56:01 PM
Mike,

It's not that I'm blowing you off, it's Charles's forum. Just because I have keys doesn't mean I drive. I will always back Charles up if he is sleeping and someone does something grossly outside forum policy. (Aurel has crossed that line in the past)

Title: Re: Lisp in Basic
Post by: RobbeK on January 08, 2015, 06:11:54 AM
Great Show, Mike,

Well, not through the 1000 page documentation of GFA  ;)   -- seems no DirectDraw available (too old ?)  , but it has bitBlt 'ing and OpenGL works too now ,   we'll c
I wonder, you surely know --  those older programming languages do they miss the more modern numeric possibilities from the newer processors ?   (i think to remember GFA died in 2002  )


best, Rob
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on January 08, 2015, 10:57:47 AM
Hi Rob,

Thanks for your appreciation. It wasn't a show-off though, it was rather a gentle push forward in the right direction. Since John allows himself such "passes" at you then I just thought why shouldn't I be allowed to do the same, if only from time to time? :D

DirectDraw is a Windows-only technology and like all their other DirectBlaBla stuff, it is OOP and interface oriented, not low-level enough to my taste, shaky and slippery, and intended primarily for C++ development environments. Fond of MS Windows as I am, I've never used these layers of MS technology for my own work and was more than happy with OpenGL. There's nothing DirectBlaBla can do that OpenGL and its peers can't.

There are basically no new numeric possibilities in i386 CPUs of today as compared to 2002. VB6 is much older than that but it still enjoys all of Windows math-wise functionality there is. It would be another question if GFA can enjoy/employ other benefits of modern CPU architectures such as e.g. multithreading et al. to their fullest, and also how efficient its native code generation is. But here I can't give you any advice because I've absolutely no personal experience with this BASIC except having read a couple of your GFA scripts so far.
Title: Re: Lisp in Basic
Post by: Arnold on March 26, 2015, 02:48:59 AM
Hello,

I have not yet read all of this thread (page 12 of 65), but I found Mike's Lisp in FSBL and also found the author's website  (http://www.cs.rit.edu/~anh/lisp_soft.html)  with the source code and documentation. Inspired by Ruben.o2bas I tried to adapt the listing to Oxygenbasic. I did not expect that this would work.

After I finally succeeded to start the program I noticed that it was incomplete and faulty. Fortunately Mike had already fixed all the errors which I found, I would not have had the patience to do this. So I shamelessly copied his code.

The program works, yet I will not waste more time with it. But would it be possible to create a working executable for Win 64bit?

I will try OxyScheme to learn a bit more about Scheme.


Roland

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on March 26, 2015, 03:52:16 AM
Hi Roland,

So I shamelessly copied his code...yet I will not waste more time with it

And you did the right thing because, frankly, this code isn't worth any other investigation and/or development. John and I invested much time in having it fixed and running in ScriptBASIC, FBSL, and OxygenBasic in parallel, only to find out that it was conceptually too limited and hopelessly slow. So, we abandoned it in favor of TinyScheme (John and his SB) and nanoscheme/OxyScheme (your humble servant and FBSL/O2), respectively. These implementations are incongruously faster and more versatile than LISP-in-BASIC.

Quote
But would it be possible to create a working executable for Win 64bit?

But is it worthwhile anyway?

Quote
I will try OxyScheme to learn a bit more about Scheme.

Please do! But Charles has added some improvements to O2 that may have rendered the OxyScheme source that I had posted on this forum inoperative. In fact, I'm waiting for a stable version of O2 to be released and then I'm eager to resume my OxyScheme effort again. I think we need Charles' comment on whether the OxyScheme source is compatible with the current release of O2 and what fixes should be added in case it isn't. I haven't looked into this matter myself yet.
Title: Re: Lisp in Basic
Post by: Charles Pegge on March 26, 2015, 04:48:40 AM

Hi Roland and Mike,

There is a maintained version of OxyScheme in projectsC. It has a few changes from Mike's original, such as indexbase 0, and some @ pointer returns.

I've had a brief session to make it compatible for 64bit operation. Few changes were required, but it needs a deep debug session or two to get it working.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on March 26, 2015, 05:37:35 AM
Hi Charles,

Thanks for commenting on OxyScheme's current status.

Did you update the assembly macros at the end of the script for 64-bit compatibility? Also, the script relies heavily on C-style setjmp/longjmp functionality that's emulated at the beginning of the script. It is my understanding that this setjmp/longjmp implementation isn't compatible with 64 bits because of the CPU registers involved. Have you been able to also fix this issue?
Title: Re: Lisp in Basic
Post by: Arnold on March 26, 2015, 06:09:13 AM
Hi Mike,

I have not yet started with OxyScheme, but I noticed that using (quit) will only freeze the console. If I use:

      case OP_QUIT '/* quit */
        print "Bye" cr "Enter..." : waitkey()
        ExitProcess(1)
        'return NIL

the console closes normally and taskmanager does not continue to show gxo2.exe. I can also compile and run the program without problems. But I do not know if there are other aspects which have to be considered.

Roland
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on March 26, 2015, 06:36:27 AM
Roland,

Please follow the dedicated OxyScheme thread (http://www.oxygenbasic.org/forum/index.php?topic=1251.0). I remember John pointing out that bug to me and there was my quick fix (http://www.oxygenbasic.org/forum/index.php?topic=1251.msg12348#msg12348) to it.
Title: Re: Lisp in Basic
Post by: Arnold on March 26, 2015, 06:42:36 AM
Hi Mike,

thank you. I was not aware of this thread.

Roland
Title: Re: Lisp in Basic
Post by: Charles Pegge on March 26, 2015, 06:56:35 AM
Mike,

Yes, I've done those 64 bit things
Any call to  __p__iob() causes instant GPF.

Is there a substitute for obtaining an _iob FILE pointer ?

I'm tracking through the startup sequence, and I'll watch out for the longjmp.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on March 26, 2015, 08:24:52 AM
Charles,

Any call to  __p__iob() causes instant GPF. Is there a substitute for obtaining an _iob FILE pointer ?

AFAIR there are three different foo exports in a 32-bit msvcrt.dll that should be aliases to the same executable code to yield the _iob FILE array pointer. But again AFAIR __p__iob() was actually the only one that did the job while the others seemed to be only stubs yielding zeros.

I'm currently under 32 bits and also I don't remember if I have any utility at hand to inspect a 64-bit DLL's exports to give you any meaningful advice. Again I should look through MinGW/GCC includes to see if there's anything particular mentioned in them for 64-bit compilation. May I reboot and check it all later on? I've got some important interaction with other correspondents at the moment that won't be very convenient to interrupt.

Quote
I'm tracking through the startup sequence, and I'll watch out for the longjmp.

Setjmp/longjmp are used to reset/recover the interpreter to its initial state after a failure due to bad Scheme user code or abnormal garbage collection states. At any rate, the #define USE_SETJMP flag can be remmed out, in which case the interpreter will simply abort after any such exception.
Title: Re: Lisp in Basic
Post by: Charles Pegge on March 26, 2015, 09:10:18 AM
Mike,

As I recall, this complexity arose from coercing MSVCRT route its console outputs through the STDOUT pipeline, so that console output could be redirected when using printf or fprintf

It could be avoided by using sprintf and feeding the strings to the standard console output.

We can let this topic rest, if you prefer. Your dynamic glsl shading idea must take priority :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on March 26, 2015, 09:59:51 AM
As I recall, this complexity arose from coercing MSVCRT route its console outputs through the STDOUT pipeline, so that console output could be redirected when using printf or fprintf

Exactly! It is an rXrs requirement that Scheme work with files and ports (evidently it dates back to the prehistoric *nix and tti times), and STDIN/OUT/ERR jugglery that's very easy to implement in C (in fact, it is its integral feature) allows us to abstract and reuse the existing source code to access those devices in all their manifestations. As soon as we decide to deviate, we (or rather I) will get OxyScheme and DynC nanoscheme out of sync. But I'm almost ready for such a sacrifice. I, for one, consider other things, e.g. a solid GUI, much more important for old-timers like LISP, Scheme and BASIC than compliance with ports/terminals/whatever else that's alien to, or unnatural for, the concepts of modern graphics OSes we're working under.

Quote
We can let this topic rest, if you prefer. Your dynamic glsl shading idea must take priority :)

You shot and missed! :P

I'm currently earning some money under camera and keylogger surveillance by my contractor, that's why I'm somewhat reluctant to interrupt the session (though I'm itching all over to do it a.s.a.p., I must admit). :D
Title: Re: Lisp in Basic
Post by: Charles Pegge on March 26, 2015, 01:55:23 PM
Spymaster!  :D

It occurred to me that, the easiest way to create Scheme with a full GUI framework would be to create a Scheme-->Basic preprocessor. In Oxygen terms, this would take the form of a customised compiler, supporting both static and dynamic compiling. Similarly in FBSL, such a scheme would be firmly linked to FBSL's frameworks and future development path.
Title: Re: Lisp in Basic
Post by: jack on March 26, 2015, 04:25:53 PM
this is a bit off topic, but speaking about code generation, one very interesting feature of the Maple CAS is the ability to  generate code from Maple Code to a variety of languages, C, C#, Fortran, Java, Javascript, VisualBasic.
it would be awesome to have such a tool to translate code from one language to another.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on March 26, 2015, 05:20:08 PM
Oh yes, imagine an IT company's IML (intermediary meta-language) Department with a dozen labs headed by Kevin-Diggins clones each developing its own IL-to-whatever translator for a fair average pay of a hundred kilobucks per capita per annum.  ;D

Seriously, the idea is in fact nothing new; that's how the .NET platform actually works. Almost every .NET scenario can be regenerated into equally functional C# or VB.NET sources. But of course a multi-language implementation is going to be so laborious that noone in his right senses would accept the challenge out of sheer faith in the FSF isms.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on March 26, 2015, 09:09:51 PM
In Oxygen terms, this would take the form of a customised compiler, supporting both static and dynamic compiling. Similarly in FBSL, such a scheme would be firmly linked to FBSL's frameworks and future development path.

Would that be a bad idea, do you think?
Title: Re: Lisp in Basic
Post by: JRS on March 26, 2015, 09:41:22 PM
@Charles - Whatever happened to your O2 to C aspirations? Is C header file support it?
Title: Re: Lisp in Basic
Post by: Charles Pegge on March 27, 2015, 12:48:33 AM
Hi Mike,

I think it's do-able with very little effort, and well worth an exploratory project.


Hi John,

It is still on my list, but I am still working on the language side of O2. It needs to grow organically and I'm seriously contemplating another 5 years of development, to complete the list.
Title: Re: Lisp in Basic
Post by: JRS on April 16, 2015, 05:37:02 PM
Request

I'm trying to put a few like examples together to show the TinyScheme and Perl extension modules and compare them with Script BASIC. What would be a fair / common example that would play in all three environments? I could use some help on defining the criteria and the TinyScheme example. I will do the Script BASIC version and maybe we can make it a group effort for the Perl example.

The goal is to show what makes each language unique and promote its strengths. In the end we should see which tool (language) is best for the job.
Title: Re: Lisp in Basic
Post by: JRS on April 16, 2015, 09:57:28 PM
Here are the times for getting the prime numbers up to 5000.

Primes in all languages (http://ubuntuforums.org/showthread.php?t=940561)

Perl: 0m0.079s
Code: Perl
  1.        
  2. $n = 5000;
  3. for($i=3;$i<=$n;$i++)
  4. {
  5.     $is_prime = 1;
  6.     for($j=2;$j<=sqrt($i);$j++){
  7.         if($i % $j == 0){
  8.             $is_prime = 0;
  9.             break;
  10.         }
  11.     }
  12.     if($is_prime == 1) {
  13.         print $i." ";
  14.     }
  15. }
  16. print "\n";
  17.  

Script BASIC: 0m0.634s
Code: Script BASIC
  1. FOR n = 2 TO 5000
  2.   FOR k = 2 TO n / 2
  3.     flag = 0
  4.     r = n % k
  5.     IF r = 0 THEN
  6.      flag = 1
  7.      GOTO done
  8.     END IF
  9.   NEXT k
  10.   done:
  11.   IF flag = 0 THEN PRINT n," "
  12. NEXT n
  13. printnl
  14.  

TinyScheme: 0m0.971s
Code: Scheme
  1. (newline)
  2. (display "start")
  3. (newline)
  4.  
  5. (define (seq x)
  6.    (let ((M '()))
  7.      (do ((i 0 (+ i 1)))
  8.          ((> i x))
  9.          (set! M (cons i M))) M ))
  10.  
  11. (define numbers (reverse (seq 4999)))
  12.  
  13. (define (sieve L)
  14.    (let ( ( len (- (length L) 2)) (vec (list->vector L)) )
  15.      (do ((i 2 (+ i 1)))
  16.          ((> i (floor (/ len 2))))
  17.  
  18.          (when (> (vector-ref vec i) 0)
  19.             (do ((j 2 (+ j 1)))
  20.                 ((> (* i j) len))
  21.  
  22.                 (vector-set! vec (* i j) 0)))) vec ))
  23.  
  24. (define (print-vec V)
  25.    (let ((len (vector-length V)) (cnt 0) )
  26.      (do (( i 2 (+ 1 i)))
  27.          (( = i (- len 1)))
  28.          (let (( item (vector-ref V i)))
  29.            (when (not (= item 0))
  30.               (set! cnt (+ 1 cnt))
  31.               (display item)
  32.               (display " ")))) cnt ))
  33.  
  34. (define (main)
  35.   (let ((cnt 0))
  36.    (newline)
  37.    (display "calculating prime-numbers < 5000")  (newline)
  38.    (display "--------------------------------")  (newline)
  39.    (set! cnt (print-vec (sieve numbers)))
  40.    (newline)
  41.    (display "that's it")
  42.    (newline)
  43.    (display cnt) (display "  prime numbers found") ))
  44.  
  45. (main)
  46.  
 

Title: Re: Lisp in Basic
Post by: Charles Pegge on April 17, 2015, 01:57:45 AM
Let me throw in an o2 assembler example :)

Code: Text
  1.   includepath "$\inc\"
  2.   include "console.inc"
  3.   sys a
  4.   mov edi,2
  5.   (
  6.     mov esi,edi
  7.     shr esi,1
  8.     mov ecx,2
  9.     (
  10.       cmp ecx,esi : jg exit  'passes prime test
  11.       mov eax,edi : xor edx,edx : div ecx
  12.       (
  13.         cmp edx,0 : jnz exit 'remainder
  14.         jmp fwd ndone        'no remainder, therefore not prime
  15.       )
  16.       inc ecx : repeat
  17.     )
  18.     pushad : a=edi : print " " & a : popad
  19.     ndone:
  20.     inc edi : cmp edi,5000 : jle repeat
  21.   )
  22.   printl "ok"
  23.   waitkey
  24.  
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 17, 2015, 02:40:28 AM
Hi,

Since none of us seems to be an expert in Perl and/or Scheme, perhaps we should try and find something at RosettaCode.org (http://rosettacode.org/wiki/Rosetta_Code)?
Title: Re: Lisp in Basic
Post by: Charles Pegge on April 17, 2015, 03:24:04 AM
Implementation using o2 projectsA/LeanLisp.

Delightfully stringy and slow :)

Code: OxygenBasic
  1. % UseSystemConsole
  2. includepath "$/inc/"
  3. include console.inc
  4. includepath ""
  5. include LispishUtil.inc
  6.  
  7. print lisp `( eval
  8.  
  9. "primes:" (cr)
  10. ( let primes " c           ; DOWNCOUNT PARAM C
  11.   ( eval
  12.     ( let primes ' 2 ' )   ; LIST WITH STARTING VALUE
  13.    ( let v 3     )        ; FIRST CANDIDATE
  14.     ( let n 1     )        ; LIST INDEX
  15.     ( let d )              ; DIVISOR
  16.     ( eval
  17.       ; CHECK EACH CANDIDATE BY USING PREVIOUS PRIMES AS DIVISORS
  18.       ( set n 1 )
  19.       ( loop ( eval
  20.         ( set d ( getmid primes n 1 ) ) ;GET NEXT PRIME DIVISOR
  21.           ( if d
  22.             ( )
  23.             ( eval ( setmid primes 0 0 v ) (exit) ) ; APPEND
  24.           )
  25.           ( if ( == 0 ( mod v d ) ) (exit) )
  26.           ( incr n ) ; NEXT PRIME D
  27.       ) ) ; eval loop
  28.       ( incr v ) ( iter c ) ; NEXT CANDIDATE
  29.     )
  30.     primes ; EXPOSE COMPLETED LIST
  31.   )
  32. ")
  33.  
  34. ( primes 1000 ) (cr)
  35. ) ;eval
  36.  
  37. ` 'end of src
  38.  
  39. waitkey
  40.  
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 17, 2015, 04:41:38 AM
Hi Charles,

What are the benchmarks for these two scripts on your PC?
Title: Re: Lisp in Basic
Post by: Peter on April 17, 2015, 05:49:43 AM
Quote
Let me throw in an o2 assembler example

only the author knows what that means. ( ), repeat, fwd, exit, and so on!
a small tutorial would be good. everything in small steps might tell us the mystery.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 17, 2015, 07:50:20 AM
only the author knows what that means. ( ), repeat, fwd, exit, and so on!
a small tutorial would be good. everything in small steps might tell us the mystery.

(http://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Hand_thumb_up.svg/332px-Hand_thumb_up.svg.png)


 :D
Title: Re: Lisp in Basic
Post by: Peter on April 17, 2015, 08:07:47 AM
Thanks Mike, that you have chosen the good side!
Title: Re: Lisp in Basic
Post by: JRS on April 17, 2015, 08:14:27 AM
@Charles - Both prime examples ran under Wine. The asm version was instant with a slight delay for the lean version. I don't have the timer utility installed on Wine yet but will sometime today.
Title: Re: Lisp in Basic
Post by: JRS on April 17, 2015, 08:30:31 AM
Script BASIC took back the lead (TS, Perl and  SB) by rewriting the SB example to work like Perl. (square root method)

Code: Script BASIC
  1. FOR i = 3 TO 5000
  2.   is_prime = 1
  3.   FOR j = 2 TO SQR(i)
  4.     IF i % j = 0 THEN
  5.       is_prime = 0
  6.       GOTO Done
  7.     END IF
  8.   NEXT
  9.   Done:
  10.   IF is_prime = 1 THEN PRINT i," "
  11. NEXT
  12. PRINTNL
  13.  


jrs@laptop:~/sb/sb22/test$ time scriba pnumsqrt.sb
3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973 4987 4993 4999

real   0m0.042s
user   0m0.038s
sys   0m0.004s
jrs@laptop:~/sb/sb22/test$

Title: Re: Lisp in Basic
Post by: Charles Pegge on April 17, 2015, 09:10:20 AM
re: o2asm and LeanLisp Prime generators:

One be a hare, the other be a tortoise. :)

But the tortoise was only given primes up to 1000, otherwise it takes at least 10 seconds for 5000.

The secrets of o2 asm

Oxygen uses magic brackets to denote a scoped block. To jump out of the block, use exit. To jump to the beginning of the block, use repeat.

labels inside a block are invisible to outside callers.

The fwd qualifier assists the linker (and programmers) by informing them that the label is further down the listing. It is also permissible to use the same label repeatedly.

These facilities give Asm some of the characteristics of a high level language by supporting block structure and localism.

Title: Re: Lisp in Basic
Post by: Peter on April 17, 2015, 09:47:10 AM
Quote
The secrets of o2 asm
  ;D
Thanks Charles.

Here something from my study:
Localism may refer to a stage at the beginning of the 19th century, the research focused on local changes in
certain organs as a cause of disease in the history of medicine.
Title: Re: Lisp in Basic
Post by: JRS on April 17, 2015, 10:22:09 AM
I'm wondering it Rob's prime numbers in TinyScheme example can be optimized like I did with SB?

Title: Re: Lisp in Basic
Post by: Charles Pegge on April 17, 2015, 12:47:03 PM
Hi John,

One further optimization: no need for a flag.

Code: Script BASIC
  1. FOR i = 3 TO 5000
  2.   FOR j = 2 TO SQR(i)
  3.     IF i % j = 0 THEN
  4.       GOTO nDone
  5.     END IF
  6.   NEXT
  7.   PRINT i," "
  8.   nDone:
  9. NEXT
  10. PRINTNL
  11.  
Title: Re: Lisp in Basic
Post by: JRS on April 17, 2015, 01:52:46 PM
Thanks Charles! Shaved a little time off the last version.

Code: Script BASIC
  1. FOR i = 3 TO 5000
  2.   FOR j = 2 TO SQR(i)
  3.     IF i % j = 0 THEN GOTO nDone
  4.   NEXT
  5.   PRINT i," "
  6.   nDone:
  7. NEXT
  8. PRINTNL
  9.  


jrs@laptop:~/sb/sb22/test$ time scriba pnsqr2.sb
3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973 4987 4993 4999

real   0m0.034s
user   0m0.028s
sys   0m0.004s
jrs@laptop:~/sb/sb22/test$

Title: Re: Lisp in Basic
Post by: JRS on April 17, 2015, 04:15:18 PM
Here is the Perl version being called as an Script BASIC extension module function.

Code: Script BASIC
  1. DECLARE SUB pl_Init ALIAS "pl_Init" LIB "sbperl"
  2. DECLARE SUB pl_Eval ALIAS "pl_Eval" LIB "sbperl"
  3. DECLARE SUB pl_GetInt ALIAS "pl_GetInt" LIB "sbperl"
  4. DECLARE SUB pl_GetDbl ALIAS "pl_GetDbl" LIB "sbperl"
  5. DECLARE SUB pl_GetStr ALIAS "pl_GetStr" LIB "sbperl"
  6. DECLARE SUB pl_Destroy ALIAS "pl_Destroy" LIB "sbperl"
  7.  
  8. pl_Init
  9.  
  10. pl_code = """
  11. $n = 5000;
  12. for($i=3;$i<=$n;$i++)
  13. {
  14.    $is_prime = 1;
  15.    for($j=2;$j<=sqrt($i);$j++){
  16.        if($i % $j == 0){
  17.            $is_prime = 0;
  18.            break;
  19.        }
  20.    }
  21.    if($is_prime == 1) {
  22.        print $i." ";
  23.    }
  24. }
  25. print "\n";
  26. """
  27. PRINTNL
  28.  
  29. pl_Eval pl_code
  30.  
  31. pl_Destroy
  32.  

Output

jrs@laptop:~/sb/sb22/test$ time scriba perlprime.sb

3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973 4987 4993 4999

real   0m0.083s
user   0m0.078s
sys   0m0.004s
jrs@laptop:~/sb/sb22/test$

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 17, 2015, 06:39:03 PM
Guys,

Y'all will spare yourselves a little PITA if you notice that prime numbers can't be even. ;)
Title: Re: Lisp in Basic
Post by: JRS on April 17, 2015, 07:13:54 PM
Guys,

Y'all will spare yourselves a little PITA if you notice that prime numbers can't be even. ;)

Hi Mike,

No noticeable improvement using a STEP 2 to skip even numbers.

Would you have time to whip up an efficient TinyScheme prime number example that emulate the SB & Perl examples?
Title: Re: Lisp in Basic
Post by: JRS on April 17, 2015, 07:26:20 PM
Here is a Python example.

Code: Python
  1. for num in range(3,5000 + 1):
  2.    if num > 1:
  3.        for i in range(2,num):
  4.            if (num % i) == 0:
  5.                break
  6.        else:
  7.            print(num),
  8.  

Output

jrs@laptop:~/python$ time python primenum.py
3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973 4987 4993 4999

real   0m0.401s
user   0m0.387s
sys   0m0.012s
jrs@laptop:~/python$

Title: Re: Lisp in Basic
Post by: JRS on April 17, 2015, 07:44:52 PM
A PHP example.

Code: PHP
  1. <?php
  2. $num =5000;
  3.  
  4. for( $j = 3; $j <= $num; $j++ )
  5. {
  6. for( $k = 2; $k < $j; $k++ )
  7. {
  8. if( $j % $k == 0 )
  9. {
  10. break;
  11. }
  12.  
  13. }
  14. if( $k == $j )
  15. echo $j." ";
  16. }
  17. echo "\n";
  18. ?>
  19.  

Output

jrs@laptop:~/php_dev$ time php prime.php
3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973 4987 4993 4999

real   0m0.152s
user   0m0.141s
sys   0m0.008s
jrs@laptop:~/php_dev$

Title: Re: Lisp in Basic
Post by: JRS on April 17, 2015, 08:10:31 PM
I welcome any improvements to the above code.

I would like to move on to the next category of tests between the major scripting engines. What would be the next logical benchmark to run?

 
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 17, 2015, 08:17:41 PM
Hi John,

No noticeable improvement using a STEP 2 to skip even numbers.

There must be because you're evaluating twice fewer values.

Quote
Would you have time to whip up an efficient TinyScheme prime number example that emulate the SB & Perl examples?

Sure. Here's the one that skips even numbers:

Code: Scheme
  1. (define (prime? n)
  2.   (if (< n 4) (> n 1)
  3.       (and (odd? n)
  4.            (let loop ((k 3))
  5.              (or (> (* k k) n)
  6.                  (and (positive? (remainder n k))
  7.                       (loop (+ k 2))))))))
  8.  
  9. (define (main)
  10.   (do ((i 3 (+ i 2)))
  11.     ((> i 4999) #t)
  12.       (if (prime? i) (begin (display i)(display " ")) "")
  13.   )
  14.   (newline)
  15. )
  16.  
  17. (main)

Here's its output on my PC:

C:\tinyscheme>timeit tinyscheme.exe primes2
3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137
 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271
 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431
 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593
 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751
 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929
 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069
 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223
 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373
 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511
 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657
 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811
 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987
 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129
 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287
 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423
 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617
 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741
 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903
 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079
 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257
 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413
 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571
 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727
 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907
 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057
 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231
 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409
 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583
 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751
 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937
 4943 4951 4957 4967 4969 4973 4987 4993 4999
Uptime 0 min :: 0 sec :: 109.420 msec


And here's Rob's output on my PC just FYI:

C:\tinyscheme>timeit tinyscheme.exe primes

start

calculating prime-numbers < 5000
--------------------------------
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 1
37 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 2
71 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 4
31 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 5
93 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 7
51 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 9
29 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 10
69 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 12
23 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 13
73 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 15
11 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 16
57 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 18
11 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 19
87 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 21
29 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 22
87 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 24
23 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 26
17 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 27
41 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 29
03 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 30
79 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 32
57 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 34
13 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 35
71 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 37
27 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 39
07 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 40
57 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 42
31 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 44
09 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 45
83 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 47
51 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 49
37 4943 4951 4957 4967 4969 4973 4987 4993 4999
that's it
669  prime numbers found
Uptime 0 min :: 0 sec :: 677.931 msec



So, I guess the result is almost 7 times faster. :)


(This code should also run in OxyScheme!)
Title: Re: Lisp in Basic
Post by: Charles Pegge on April 17, 2015, 08:19:12 PM
A parser would be quite interesting to do, since it tests the proficiency of a language to handle strings.
Title: Re: Lisp in Basic
Post by: JRS on April 17, 2015, 08:32:50 PM
Thanks Mike for the TinyScheme Prime Numbers example. Here is your example running as a Script BASIC extension module function call.

Code: Script BASIC
  1. IMPORT ts.inc
  2.  
  3. sc = TS_New()
  4. TS_Cmd sc, "(load \"init.scm\")"
  5. ts_src = """
  6. (define (prime? n)
  7.  (if (< n 4) (> n 1)
  8.      (and (odd? n)
  9.           (let loop ((k 3))
  10.             (or (> (* k k) n)
  11.                 (and (positive? (remainder n k))
  12.                      (loop (+ k 2))))))))
  13.  
  14. (define (main)
  15.  (do ((i 3 (+ i 2)))
  16.    ((> i 4999) #t)
  17.      (if (prime? i) (begin (display i)(display " ")) "")
  18.  )
  19.  (newline)
  20. )
  21.  
  22. (main)
  23. """
  24. PRINT TS_Cmd(sc, ts_src),"\n"
  25. TS_Close sc
  26.  

Output

jrs@laptop:~/sb/sb22/TS$ time scriba tspnmike.sb
3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973 4987 4993 4999

real   0m0.394s
user   0m0.392s
sys   0m0.000s
jrs@laptop:~/sb/sb22/TS$


@Charles - parser -  You must have been reading my mind.  :)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 17, 2015, 08:41:55 PM
Parsers? In interpretative languages?!  :o
Title: Re: Lisp in Basic
Post by: JRS on April 17, 2015, 09:12:50 PM
Here is a brute force XML parser in Script BASIC.

xmlparse.sb
Code: Script BASIC
  1. IMPORT t.bas
  2.  
  3. xml = t::LoadString("sample.xml")
  4.  
  5. SPLITA xml BY ">" TO a
  6.  
  7. FOR x = 0 TO UBOUND(a)
  8.   IF LEFT(TRIM(a[x]),1) = "<" THEN GOTO IT
  9.   p = INSTR(a[x],"<")
  10.   PRINT MID(a[x],p+2) & " = " & LEFT(a[x],p-1),"\n"
  11. IT:
  12. NEXT
  13.  


Example XML residential listing
Code: XML
  1. <Listings xmlns="http://www.nwmls.com/Schemas/Standard/StandardXML1_1.xsd">
  2.         <Residential>
  3.                 <LN>62981</LN>
  4.                 <PTYP>RESI</PTYP>
  5.                 <LAG>27022</LAG>
  6.                 <ST>CT</ST>
  7.                 <LP>599950.00</LP>
  8.                 <SP>0.00</SP>
  9.                 <OLP>599950.00</OLP>
  10.                 <HSN>4538</HSN>
  11.                 <DRP/>
  12.                 <STR>23rd</STR>
  13.                 <SSUF>Ave</SSUF>
  14.                 <DRS>SW</DRS>
  15.                 <UNT/>
  16.                 <CIT>Seattle</CIT>
  17.                 <STA>WA</STA>
  18.                 <ZIP>98126</ZIP>
  19.                 <PL4/>
  20.                 <BR>5.00</BR>
  21.                 <BTH>3.50</BTH>
  22.                 <ASF>3650</ASF>
  23.                 <LSF>4800</LSF>
  24.                 <UD>2010-04-24 14:59:25</UD>
  25.                 <AR>140</AR>
  26.                 <DSRNUM>7215</DSRNUM>
  27.                 <LDR>2010-04-24 00:00:00</LDR>
  28.                 <LD>2010-04-24 00:00:00</LD>
  29.                 <CLO>1800-01-01 00:00:00</CLO>
  30.                 <YBT>2010</YBT>
  31.                 <LO>1401</LO>
  32.                 <TAX>1773600264</TAX>
  33.                 <MAP>594</MAP>
  34.                 <GRDX>G</GRDX>
  35.                 <GRDY>4</GRDY>
  36.                 <SAG>0</SAG>
  37.                 <SO>0</SO>
  38.                 <NIA>Y</NIA>
  39.                 <MR>Third of three New Contemporary Homes w/fantastic open floor plans and great level and fenced backyards.These homes have wonderful tall ceilings,designer paint,fully wrapped windows,solid core/glass int doors and top of the line strand Bamboo flrs.The kitchen is an entertainers dream w/an enormous open eating bar,honed granite counters,custom wood cabinets,top of the line stainless steel appls and french doors to the ent backyard. Quality and Designer features from top to Bottom, a must see!!</MR>
  40.                 <LONG>-122.362210</LONG>
  41.                 <LAT>47.561975</LAT>
  42.                 <PDR>1800-01-01 00:00:00</PDR>
  43.                 <CLA>0</CLA>
  44.                 <SHOADR>Y</SHOADR>
  45.                 <DD>From Delridge Way head east on Oregon which becomes 23rd.</DD>
  46.                 <AVDT>1800-01-01 00:00:00</AVDT>
  47.                 <INDT>1800-01-01 00:00:00</INDT>
  48.                 <COU>King</COU>
  49.                 <CDOM>0</CDOM>
  50.                 <CTDT>2010-04-24 00:00:00</CTDT>
  51.                 <SCA>0</SCA>
  52.                 <SCO>0</SCO>
  53.                 <VIRT/>
  54.                 <SD>SEA</SD>
  55.                 <SDT>2010-04-24 00:00:00</SDT>
  56.                 <FIN/>
  57.                 <MAPBOOK>THOM</MAPBOOK>
  58.                 <DSR>Pigeon Point</DSR>
  59.                 <QBT>0</QBT>
  60.                 <LSZS/>
  61.                 <HSNA/>
  62.                 <COLO>0</COLO>
  63.                 <PIC>1</PIC>
  64.                 <ADU/>
  65.                 <ARC>K</ARC>
  66.                 <BDC/>
  67.                 <BDL>2</BDL>
  68.                 <BDM>0</BDM>
  69.                 <BDU>3</BDU>
  70.                 <BLD>JDR Development Inc</BLD>
  71.                 <BLK>14</BLK>
  72.                 <BRM/>
  73.                 <BUS>Y</BUS>
  74.                 <DNO>L</DNO>
  75.                 <DRM>M</DRM>
  76.                 <EFR/>
  77.                 <EL/>
  78.                 <ENT>M</ENT>
  79.                 <F17>A</F17>
  80.                 <FAM>M</FAM>
  81.                 <FBG>0</FBG>
  82.                 <FBL>1</FBL>
  83.                 <FBM>0</FBM>
  84.                 <FBT>3</FBT>
  85.                 <FBU>2</FBU>
  86.                 <FP>1</FP>
  87.                 <FPL>0</FPL>
  88.                 <FPM>1</FPM>
  89.                 <FPU>0</FPU>
  90.                 <GAR>2</GAR>
  91.                 <HBG>0</HBG>
  92.                 <HBL>0</HBL>
  93.                 <HBM>1</HBM>
  94.                 <HBT>1</HBT>
  95.                 <HBU>0</HBU>
  96.                 <HOD>0</HOD>
  97.                 <JH/>
  98.                 <KES>M</KES>
  99.                 <KIT/>
  100.                 <LRM>M</LRM>
  101.                 <LSD/>
  102.                 <LSZ/>
  103.                 <LT>16</LT>
  104.                 <MBD>U</MBD>
  105.                 <MHM/>
  106.                 <MHN/>
  107.                 <MHS/>
  108.                 <MOR>0</MOR>
  109.                 <NC>U</NC>
  110.                 <POC>SEA</POC>
  111.                 <POL/>
  112.                 <PRJ>Cottage Grove # 3</PRJ>
  113.                 <PTO>Y</PTO>
  114.                 <TQBT>0</TQBT>
  115.                 <RRM>L</RRM>
  116.                 <SAP>0</SAP>
  117.                 <SFF>0</SFF>
  118.                 <SFS>Per Builder Plans</SFS>
  119.                 <SFU>0</SFU>
  120.                 <SH/>
  121.                 <SML>Y</SML>
  122.                 <SNR>N</SNR>
  123.                 <STY>18</STY>
  124.                 <SWC>SEA</SWC>
  125.                 <TBG>0</TBG>
  126.                 <TBL>0</TBL>
  127.                 <TBM>0</TBM>
  128.                 <TBU>0</TBU>
  129.                 <TX>0</TX>
  130.                 <TXY>0</TXY>
  131.                 <UTR>U</UTR>
  132.                 <WAC>SEA</WAC>
  133.                 <WFG/>
  134.                 <WHT/>
  135.                 <APS>A|D|E|F|G</APS>
  136.                 <BDI>E</BDI>
  137.                 <BSM>A|B</BSM>
  138.                 <ENS>B</ENS>
  139.                 <EXT>J|E</EXT>
  140.                 <FEA>A|D|F|G|J|M|P|T</FEA>
  141.                 <FLS>J|A|G</FLS>
  142.                 <FND>E|F</FND>
  143.                 <GR>C</GR>
  144.                 <HTC>B</HTC>
  145.                 <LDE>H|J</LDE>
  146.                 <LTV>E|F</LTV>
  147.                 <POS>A</POS>
  148.                 <RF>C</RF>
  149.                 <SIT>G|H|M|Y|N</SIT>
  150.                 <SWR>A</SWR>
  151.                 <TRM>B|C</TRM>
  152.                 <VEW>D|L</VEW>
  153.                 <WAS>D</WAS>
  154.                 <WFT/>
  155.                 <BUSR/>
  156.                 <CMFE/>
  157.                 <ECRT/>
  158.                 <ZJD>A</ZJD>
  159.                 <ZNC>SF 5000</ZNC>
  160.                 <ProhibitBLOG>Y</ProhibitBLOG>
  161.                 <AllowAVM>Y</AllowAVM>
  162.                 <PARQ>N</PARQ>
  163.                 <BREO>N</BREO>
  164.         </Residential>
  165. </Listings>
  166.  

Results

jrs@laptop:~/sb/sb22/test$ time scriba xmlparse.sb
LN = 62981
PTYP = RESI
LAG = 27022
ST = CT
LP = 599950.00
SP = 0.00
OLP = 599950.00
HSN = 4538
STR = 23rd
SSUF = Ave
DRS = SW
CIT = Seattle
STA = WA
ZIP = 98126
BR = 5.00
BTH = 3.50
ASF = 3650
LSF = 4800
UD = 2010-04-24 14:59:25
AR = 140
DSRNUM = 7215
LDR = 2010-04-24 00:00:00
LD = 2010-04-24 00:00:00
CLO = 1800-01-01 00:00:00
YBT = 2010
LO = 1401
TAX = 1773600264
MAP = 594
GRDX = G
GRDY = 4
SAG = 0
SO = 0
NIA = Y
MR = Third of three New Contemporary Homes w/fantastic open floor plans and great level and fenced backyards.These homes have wonderful tall ceilings,designer paint,fully wrapped windows,solid core/glass int doors and top of the line strand Bamboo flrs.The kitchen is an entertainers dream w/an enormous open eating bar,honed granite counters,custom wood cabinets,top of the line stainless steel appls and french doors to the ent backyard. Quality and Designer features from top to Bottom, a must see!!
LONG = -122.362210
LAT = 47.561975
PDR = 1800-01-01 00:00:00
CLA = 0
SHOADR = Y
DD = From Delridge Way head east on Oregon which becomes 23rd.
AVDT = 1800-01-01 00:00:00
INDT = 1800-01-01 00:00:00
COU = King
CDOM = 0
CTDT = 2010-04-24 00:00:00
SCA = 0
SCO = 0
SD = SEA
SDT = 2010-04-24 00:00:00
MAPBOOK = THOM
DSR = Pigeon Point
QBT = 0
COLO = 0
PIC = 1
ARC = K
BDL = 2
BDM = 0
BDU = 3
BLD = JDR Development Inc
BLK = 14
BUS = Y
DNO = L
DRM = M
ENT = M
F17 = A
FAM = M
FBG = 0
FBL = 1
FBM = 0
FBT = 3
FBU = 2
FP = 1
FPL = 0
FPM = 1
FPU = 0
GAR = 2
HBG = 0
HBL = 0
HBM = 1
HBT = 1
HBU = 0
HOD = 0
KES = M
LRM = M
LT = 16
MBD = U
MOR = 0
NC = U
POC = SEA
PRJ = Cottage Grove # 3
PTO = Y
TQBT = 0
RRM = L
SAP = 0
SFF = 0
SFS = Per Builder Plans
SFU = 0
SML = Y
SNR = N
STY = 18
SWC = SEA
TBG = 0
TBL = 0
TBM = 0
TBU = 0
TX = 0
TXY = 0
UTR = U
WAC = SEA
APS = A|D|E|F|G
BDI = E
BSM = A|B
ENS = B
EXT = J|E
FEA = A|D|F|G|J|M|P|T
FLS = J|A|G
FND = E|F
GR = C
HTC = B
LDE = H|J
LTV = E|F
POS = A
RF = C
SIT = G|H|M|Y|N
SWR = A
TRM = B|C
VEW = D|L
WAS = D
ZJD = A
ZNC = SF 5000
ProhibitBLOG = Y
AllowAVM = Y
PARQ = N
BREO = N

 =

real   0m0.038s
user   0m0.005s
sys   0m0.002s
jrs@laptop:~/sb/sb22/test$
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 17, 2015, 09:16:59 PM
Oh, I see. Such parsers...
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 18, 2015, 07:02:15 AM
(This code should also run in OxyScheme!)

It runs but it doesn't produce the expected results. There must be still some bugs somewhere in OxyScheme...  :(
Title: Re: Lisp in Basic
Post by: JRS on April 18, 2015, 07:07:13 AM
(This code should also run in OxyScheme!)

It runs but it doesn't produce the expected results. There must be still some bugs somewhere in OxyScheme...  :(

I was surprised how fast your TinyScheme version was. PHP was also a surprise.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 18, 2015, 08:24:35 AM
Hi John,

This is the executable that I've compiled using MS VC6 with the /O2 (favor fast code) switch. It is only 108KB large including the DL interface. Actually, once timeit tinyscheme.exe primes2 is run several times and all data is in the disk cache, the script gets executed substantially faster. Note that timeit tinyscheme.exe own exec time (init.scm included) is as low as 6 msec only:

C:\tinyscheme>timeit tinyscheme.exe primes2
3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137
 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271
 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431
 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593
 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751
 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929
 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069
 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223
 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373
 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511
 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657
 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811
 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987
 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129
 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287
 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423
 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617
 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741
 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903
 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079
 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257
 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413
 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571
 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727
 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907
 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057
 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231
 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409
 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583
 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751
 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937
 4943 4951 4957 4967 4969 4973 4987 4993 4999
Uptime 0 min :: 0 sec :: 92.245 msec
Title: Re: Lisp in Basic
Post by: JRS on April 18, 2015, 09:27:26 AM
Here is my TinyScheme as a 64 bit library and called from Script BASIC raw execution speed.

Code: Script BASIC
  1. IMPORT ts.inc
  2.  
  3. sc = TS_New()
  4. TS_Cmd sc, "(load \"init.scm\")"
  5. TS_Close sc
  6.  


jrs@laptop:~/sb/sb22/TS$ time scriba tsraw.sb

real   0m0.140s
user   0m0.007s
sys   0m0.008s
jrs@laptop:~/sb/sb22/TS$

Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 18, 2015, 11:15:44 AM
John,

AFAIK TinyScheme loads its init.scm automatically at app start and throws a Could not open file init.scm warning if the file is missing. If it is then TinyScheme will work but its functionality and compliance with R5RS will be severely compromised because init.scm is effectively an R5RS runtime library.

Are you sure you can't confine it to just letting it start all by itself? Probably "(load \"init.scm\")" is redundant? TinyScheme wouldn't complain about loading a file more than once... :-\
Title: Re: Lisp in Basic
Post by: JRS on April 18, 2015, 11:22:16 AM
I'm pretty sure if your calling TinyScheme as a library, loading init.scm is a manual process. This is what is reported running your Prime Number example without loading the init.scm first.


jrs@laptop:~/sb/sb22/TS$ scriba tspnmike.sb
Error: eval: unbound variable: do
jrs@laptop:~/sb/sb22/TS$


Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 18, 2015, 11:45:42 AM
That's correct. As seen in the sources, init.scm is loaded automatically in the main() function of an executable but not in a library. Thanks for trying it out anyway.
Title: Re: Lisp in Basic
Post by: JRS on April 18, 2015, 01:10:31 PM
I'm happy with the TinyScheme and Perl extension module interfaces so far. It's a nice addition to Script BASIC. I hope it attracts more users.

I thought I would try to do a time test without loading the init.scm (a fairly extensive library in text) but it segment faulted. I added a simple (quit) and it worked.

I have to say that extending the TinyScheme language with the init.scm is a easy and painless way to go. It also serves as a learning reference to some of the more advanced features of the language. I hope to follow Mike's lead and become more proficient in Scheme.

Code: Script BASIC
  1. IMPORT ts.inc
  2.  
  3. sc = TS_New()
  4. TS_Cmd sc, "(quit)"
  5. TS_Close sc
  6.  


jrs@laptop:~/sb/sb22/TS$ time scriba tsraw.sb

real   0m0.003s
user   0m0.002s
sys   0m0.000s
jrs@laptop:~/sb/sb22/TS$


Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 18, 2015, 05:52:36 PM
Below is a typical reading I'm getting when running the "raw" script with a sole (quit) inside. But this reading includes the time it takes TinyScheme to load its init.scm script before it loads the "raw" script and quits immediately.

(TimeIt is an FBSL console executable, and FBSL uses a console that's somewhat wider than the system default.)

.
Title: Re: Lisp in Basic
Post by: JRS on April 18, 2015, 05:57:08 PM
@Mike - Is TinyScheme usable without the init.scm extension library? Do you feel it's worth making an optional (load) requirement rather than forcing it on you as a default?

Attached is a millisecond to second conversion to help translate the different times being shown.

.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 18, 2015, 06:12:24 PM
I would say no, John. As per R5RS, the Scheme syntax is divided more or less evenly between standard and library keywords and procedures. Standard syntax is implemented in the binary while the library is written in Scheme proper and is to the language what system header files with their macros are to C. For example, there are no iteration constructs in Scheme but the library (init.scm in this case) defines the corresponding macros for general-purpose Scheme scripts to be usable and executable in TinyScheme.

Neither Rob's nor my script would be runnable without init.scm which, among many other things, also defines the (do) iteration macro.
Title: Re: Lisp in Basic
Post by: JRS on April 18, 2015, 06:37:45 PM
I'm thinking that a Script BASIC batch command processor could be built as a compiled SB to C script that uses SB, Perl and TinyScheme (text) scripts as user code. SB supports redirection on the command line as well as standard error. I never could get my arms around bash and other batch languages to do anything beyond simple tasks.  :-\

What would be cool is to do the above but do the processing on the Script BASIC sbhttpd multi-threaded application server.  8)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 18, 2015, 06:53:47 PM
You know I hate the console with all my heart, and FBSL v1 was originally built to escape from the Windows batch processor. I'm afraid I can't be of much help to you with this, especially on Linux. :)

Just in case, I'd like to point out again that TinyScheme is equipped with its own Scheme-to-dynamic-library interface (referenced as "dl"/"dynload" in the sources). I guess it extends to Linux too. So, TinyScheme can address 3rd party DLLs/SOs directly from Scheme code without any additional intermediation. Perhaps this can stimulate your imagination towards some scenarios that haven't yet been considered.
Title: Re: Lisp in Basic
Post by: JRS on April 18, 2015, 06:59:54 PM
Quote
Perhaps this can stimulate your imagination towards some scenarios that haven't yet been considered.

Like a Linux version of Script BASIC DYC or DLLC would be nice. I think I have the SQLite TinyScheme extension module working in this manor.

I'm also wondering what Perl may offer in this area. As AIR mention on the old BP.org site, Perl has an extensive 3rd party extension library. Just USE.
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 18, 2015, 07:24:15 PM
It's difficult for me to talk in terms of SQLite or Linux system libraries, but under Windows, it could mean, for example, writing an .scm library that would interface with user32.dll, gdi32.dll and opengl32.dll APIs, define a set of high-level macros and procedures on top of them, and using this library as an OpenGL-capable windowed GUI with standard forms, controls, dialogs and what not instead of that crooked Java trash Rob was polluting our gear with. :D

Tell you more, single-threaded nanoscheme/OxyScheme are my minimal extensions to the Public Domain code that was used to develop multi-threaded TinyScheme as we see it now. In fact there's very little difference between the two if we put aside the common access conflict prevention trickery that TinyScheme is full of. Theoretically there's nothing that can basically interfere if we choose to expand the nanoscheme/OxyScheme project into a full-blown microscheme/PeroxyScheme multi-threaded monster based off of TinyScheme sources. :)
Title: Re: Lisp in Basic
Post by: JRS on April 18, 2015, 07:54:55 PM
Quote
It's difficult for me to talk in terms of SQLite or Linux system libraries, but under Windows, it could mean, for example, writing an .scm library that would interface with user32.dll, gdi32.dll and opengl32.dll APIs, define a set of high-level macros and procedures on top of them, and using this library as an OpenGL-capable windowed GUI with standard forms, controls, dialogs and what not instead of that crooked Java trash Rob was polluting our gear with.

Could you post a simple example of the TinyScheme FFI calling a Windows message box as a .scm?

Code: Script BASIC
  1. INCLUDE dyc.bas
  2.  
  3. a$ = "message text" & CHR(0)
  4. PRINT dyc::dyc("ms,i,USER32.DLL,MessageBox,PZZL",0,a$,"title",3)
  5.  

FYI

Here is the Script BASIC sbhttpd server running the CGI echo example on Koding.com (http://scriptbasic.koding.io/home/echo.sb).
Title: Re: Lisp in Basic
Post by: JRS on April 18, 2015, 09:47:03 PM
Here is the TinyScheme Prime Number example that Mike wrote running under sbhttpd.

http://scriptbasic.koding.io/home/webscheme

Code: Script BASIC
  1. IMPORT cgi.bas
  2. IMPORT ts.inc
  3.  
  4. OPTION cgi$Method cgi::GET
  5. cgi::Header 200,"text/html"
  6.  
  7. sc = TS_New()
  8. TS_Cmd sc, "(load \"/home/scriptbasic/sbweb/init.scm\")"
  9. ts_src = """
  10. (define (prime? n)
  11.  (if (< n 4) (> n 1)
  12.      (and (odd? n)
  13.           (let loop ((k 3))
  14.             (or (> (* k k) n)
  15.                 (and (positive? (remainder n k))
  16.                      (loop (+ k 2))))))))
  17.  
  18. (define (main)
  19.  (do ((i 3 (+ i 2)))
  20.    ((> i 4999) #t)
  21.      (if (prime? i) (begin (display i)(display " ")) "")
  22.  )
  23.  (newline)
  24. )
  25.  
  26. (main)
  27. """
  28. PRINT """
  29. <html>
  30. <body>
  31. """ & TS_Cmd(sc, ts_src) & """
  32. </body>
  33. </html>
  34. """
  35. TS_Close sc
  36.  
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 18, 2015, 11:27:41 PM
Hehe, nice! :)


Sorry but I can't provide the example yet. The DLL interface that TS currently supports cannot work with Windows API directly. Instead, it expects the DLLs to be tailored to cater for TS so that the DLL is the active component in the link to establish the connection while TS remains almost entirely passive. In other words, TS would require either custom DLL proxies to be used similar to SB or the dynload module code to be extended/reworked so that TS itself can do what a normal Windows application would do under similar circumstances.

The older regexp and tsx modules you used to report here and on the SB site earlier were tailored to that model. But it is totally unnatural and too restrictive for a Windows application, whether executable or library.

I'll look into the matter more closely and will report back later about my findings.
Title: Re: Lisp in Basic
Post by: JRS on April 18, 2015, 11:32:46 PM
Sounds like the same issue with using SB extension module DLL/SO libraries. (custom calling methods)
Title: Re: Lisp in Basic
Post by: Mike Lobanovsky on April 18, 2015, 11:59:17 PM
Yeah, and it's totally beyond me why anyone would deliberately develop such restrictive and restricted functionality for as versatile an application as TinyScheme. Perhaps this was just another case when "the community" started to uncontrollably commit their unqualified "improvements" and "extensions" to an advanced project's main trunk... ::)


Is there any way in Linux to explore an SO's entry point addresses and literal function names like Windows LoadLibrary()/GetProcAddress() do?

[EDIT] More specifically, does an ELF format header contain something like a PE export table with literal (or mangled) function names and entry points?
Title: Re: Lisp in Basic
Post by: JRS on April 19, 2015, 10:41:07 AM
Here is a Perl example of parsing the XML MLS listing example in a previous post.

Code: Perl
  1. use strict;
  2. use XML::Simple;
  3. use Data::Dumper;
  4.  
  5. my $listing = XMLin('sample.xml');
  6.  
  7. print Dumper($listing);
  8.  

Output

jrs@laptop:~/sb/sb22/test$ time perl getxml.pl
$VAR1 = {
          'xmlns' => 'http://www.nwmls.com/Schemas/Standard/StandardXML1_1.xsd',
          'Residential' => {
                           'SNR' => 'N',
                           'ProhibitBLOG' => 'Y',
                           'OLP' => '599950.00',
                           'FPM' => '1',
                           'INDT' => '1800-01-01 00:00:00',
                           'SAP' => '0',
                           'MR' => 'Third of three New Contemporary Homes w/fantastic open floor plans and great level and fenced backyards.These homes have wonderful tall ceilings,designer paint,fully wrapped windows,solid core/glass int doors and top of the line strand Bamboo flrs.The kitchen is an entertainers dream w/an enormous open eating bar,honed granite counters,custom wood cabinets,top of the line stainless steel appls and french doors to the ent backyard. Quality and Designer features from top to Bottom, a must see!!',
                           'VIRT' => {},
                           'BLK' => '14',
                           'TBL' => '0',
                           'FBU' => '2',
                           'MBD' => 'U',
                           'ECRT' => {},
                           'ZIP' => '98126',
                           'BDI' => 'E',
                           'LSZS' => {},
                           'WHT' => {},
                           'LT' => '16',
                           'ENS' => 'B',
                           'PTYP' => 'RESI',
                           'PDR' => '1800-01-01 00:00:00',
                           'TBU' => '0',
                           'DNO' => 'L',
                           'LDE' => 'H|J',
                           'MHS' => {},
                           'LRM' => 'M',
                           'SHOADR' => 'Y',
                           'HTC' => 'B',
                           'GRDX' => 'G',
                           'LONG' => '-122.362210',
                           'LSD' => {},
                           'STY' => '18',
                           'GAR' => '2',
                           'BRM' => {},
                           'BREO' => 'N',
                           'YBT' => '2010',
                           'TX' => '0',
                           'BSM' => 'A|B',
                           'FP' => '1',
                           'FND' => 'E|F',
                           'TRM' => 'B|C',
                           'SFF' => '0',
                           'SCA' => '0',
                           'FLS' => 'J|A|G',
                           'LO' => '1401',
                           'DSR' => 'Pigeon Point',
                           'DRS' => 'SW',
                           'KES' => 'M',
                           'JH' => {},
                           'WFT' => {},
                           'SFU' => '0',
                           'ARC' => 'K',
                           'BLD' => 'JDR Development Inc',
                           'ADU' => {},
                           'FBM' => '0',
                           'BDM' => '0',
                           'EFR' => {},
                           'FEA' => 'A|D|F|G|J|M|P|T',
                           'GR' => 'C',
                           'EXT' => 'J|E',
                           'TQBT' => '0',
                           'FPU' => '0',
                           'STA' => 'WA',
                           'AllowAVM' => 'Y',
                           'UNT' => {},
                           'FPL' => '0',
                           'POS' => 'A',
                           'PTO' => 'Y',
                           'LSF' => '4800',
                           'RRM' => 'L',
                           'HBM' => '1',
                           'AR' => '140',
                           'TAX' => '1773600264',
                           'WFG' => {},
                           'EL' => {},
                           'SSUF' => 'Ave',
                           'RF' => 'C',
                           'SFS' => 'Per Builder Plans',
                           'PL4' => {},
                           'SWC' => 'SEA',
                           'BR' => '5.00',
                           'LP' => '599950.00',
                           'PIC' => '1',
                           'CIT' => 'Seattle',
                           'POC' => 'SEA',
                           'HBT' => '1',
                           'AVDT' => '1800-01-01 00:00:00',
                           'HBG' => '0',
                           'SH' => {},
                           'KIT' => {},
                           'SD' => 'SEA',
                           'SWR' => 'A',
                           'BUSR' => {},
                           'QBT' => '0',
                           'LAG' => '27022',
                           'HSN' => '4538',
                           'CTDT' => '2010-04-24 00:00:00',
                           'DSRNUM' => '7215',
                           'SML' => 'Y',
                           'FIN' => {},
                           'LAT' => '47.561975',
                           'WAC' => 'SEA',
                           'NC' => 'U',
                           'PARQ' => 'N',
                           'ZNC' => 'SF 5000',
                           'UD' => '2010-04-24 14:59:25',
                           'BTH' => '3.50',
                           'HSNA' => {},
                           'HOD' => '0',
                           'HBU' => '0',
                           'DD' => 'From Delridge Way head east on Oregon which becomes 23rd.',
                           'NIA' => 'Y',
                           'PRJ' => 'Cottage Grove # 3',
                           'LD' => '2010-04-24 00:00:00',
                           'FBT' => '3',
                           'FBG' => '0',
                           'LTV' => 'E|F',
                           'SDT' => '2010-04-24 00:00:00',
                           'ST' => 'CT',
                           'BDC' => {},
                           'SAG' => '0',
                           'SCO' => '0',
                           'LDR' => '2010-04-24 00:00:00',
                           'APS' => 'A|D|E|F|G',
                           'TBG' => '0',
                           'VEW' => 'D|L',
                           'BDU' => '3',
                           'ASF' => '3650',
                           'HBL' => '0',
                           'POL' => {},
                           'COLO' => '0',
                           'MOR' => '0',
                           'DRP' => {},
                           'DRM' => 'M',
                           'F17' => 'A',
                           'MAPBOOK' => 'THOM',
                           'BUS' => 'Y',
                           'CMFE' => {},
                           'ENT' => 'M',
                           'WAS' => 'D',
                           'CDOM' => '0',
                           'CLA' => '0',
                           'LN' => '62981',
                           'MHN' => {},
                           'UTR' => 'U',
                           'LSZ' => {},
                           'COU' => 'King',
                           'ZJD' => 'A',
                           'TXY' => '0',
                           'FAM' => 'M',
                           'MHM' => {},
                           'SIT' => 'G|H|M|Y|N',
                           'MAP' => '594',
                           'GRDY' => '4',
                           'SO' => '0',
                           'TBM' => '0',
                           'CLO' => '1800-01-01 00:00:00',
                           'BDL' => '2',
                           'FBL' => '1',
                           'SP' => '0.00',
                           'STR' => '23rd'
                         }
        };

real   0m0.091s
user   0m0.086s
sys   0m0.004s
jrs@laptop:~/sb/sb22/test$