Author Topic: Lisp in Basic  (Read 208166 times)

0 Members and 1 Guest are viewing this topic.

JRS

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

« Last Edit: September 27, 2014, 12:27:41 AM by John »

RobbeK

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

 

RobbeK

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



.
« Last Edit: September 27, 2014, 06:20:08 AM by RobbeK »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #858 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.)
« Last Edit: September 27, 2014, 10:04:34 AM by Mike Lobanovsky »

JRS

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

 

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #860 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.
« Last Edit: September 27, 2014, 09:50:57 AM by Mike Lobanovsky »

RobbeK

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

JRS

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

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #863 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. :)
« Last Edit: September 27, 2014, 10:42:57 AM by Mike Lobanovsky »

Mike Lobanovsky

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

JRS

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

Mike Lobanovsky

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

JRS

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

RobbeK

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

.
« Last Edit: September 27, 2014, 01:09:10 PM by RobbeK »

JRS

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