Author Topic: Lisp in Basic  (Read 208380 times)

0 Members and 3 Guests are viewing this topic.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #495 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

.
« Last Edit: August 17, 2014, 12:10:43 PM by Mike Lobanovsky »

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #496 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 )



.
« Last Edit: August 17, 2014, 12:49:07 PM by RobbeK »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #497 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. :)

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #498 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.

JRS

  • Guest
Re: Lisp in Basic
« Reply #499 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.

« Last Edit: August 17, 2014, 02:46:50 PM by John »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #500 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.
« Last Edit: August 17, 2014, 03:52:24 PM by Mike Lobanovsky »

JRS

  • Guest
Re: Lisp in Basic
« Reply #501 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.

JRS

  • Guest
Re: Lisp in Basic
« Reply #502 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.
« Last Edit: August 17, 2014, 03:36:47 PM by John »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #503 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.

JRS

  • Guest
Re: Lisp in Basic
« Reply #504 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?




JRS

  • Guest
Re: Lisp in Basic
« Reply #505 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?


.
« Last Edit: August 17, 2014, 09:35:04 PM by John »

JRS

  • Guest
Re: Lisp in Basic
« Reply #506 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$

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #507 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

.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #508 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.




Aurel

  • Guest
Re: Lisp in Basic
« Reply #509 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.