Author Topic: Lisp in Basic  (Read 208229 times)

0 Members and 4 Guests are viewing this topic.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #345 on: August 11, 2014, 11:39:26 AM »
Hello John,

Based on Charles' input in this thread, 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.

Charles Pegge

  • Guest
Re: Lisp in Basic
« Reply #346 on: August 11, 2014, 11:46:54 AM »
Would variants help? SB uses int/double/string within its variant construct.

JRS

  • Guest
Re: Lisp in Basic
« Reply #347 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.
« Last Edit: August 11, 2014, 12:50:02 PM by John »

Mike Lobanovsky

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

Charles Pegge

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

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #350 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 ... :(
« Last Edit: August 11, 2014, 04:26:56 PM by Mike Lobanovsky »

JRS

  • Guest
Re: Lisp in Basic
« Reply #351 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?
« Last Edit: August 11, 2014, 03:31:11 PM by John »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #352 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.
« Last Edit: August 11, 2014, 04:09:34 PM by Mike Lobanovsky »

JRS

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


Mike Lobanovsky

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

Mike Lobanovsky

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

JRS

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


.
« Last Edit: August 11, 2014, 04:34:33 PM by John »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #357 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
« Last Edit: August 11, 2014, 04:49:24 PM by Mike Lobanovsky »

JRS

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


JRS

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