Author Topic: Newbie Question ..  (Read 9012 times)

0 Members and 1 Guest are viewing this topic.

RobbeK

  • Guest
Newbie Question ..
« on: June 04, 2014, 10:19:25 AM »
Hi all,

I'm new here, (though many names read/sound familiar ;-)  ..  posted this on the tB forum, (maybe not the correct place to do so)..
The last weeks I've been busy, coding some graphical interfaces for old (free) Lisps , and a flat memory for those interface in O2.
(curiously, while some Lisps promise a continuous memory model for strings - it is segmented in blocks (big ones) by pointers ).
The best way imho was to allocate and de-allocate addressable memory with O2  ; it works fine (in fact I need these to set up screen buffers without using OpenGL )   ..  DrRacket Scheme (aka MIT Scheme) does this without any problem, but it's bytcode compiliation (be it with GNU Lightning JIT ) and the speed is way below Oxygen  ;. )   etc..
I'll just quote _____________

Hi Charles, (or any one else)

I did some things in Linux -- (there are much more packages available for Lisp's running under *NIX ... but , but the graphic packages are so old it's not so nice any more ... found some with a TI (texas instruments) signature from the mid 1980's still used as the standard .. , and one package (unfinished I think - Vigil (Russian)) not documented ) considers also flat memory arrays (skipping the Lisp pointer chains ) .. (something I could do with O2 running under Windows)
As I have everything I need under Win .. the question .. hm ... you by any chance , is there .. maybe .. an O2 compiled for Linux ?? ( I need those DLL's converted to .so 's ) ( I have fbc for Linux and can do it, but I prefer Oxygen for job ).

Speaking about fb, .. why does it use those "lib.... .a" files ? iirc you use Freebasic too ? .. what are these , static libs ?? The Lisp accepts *.so files, but fb seems to give an error ( related with the linker ?)

best Rob  (thanks in advance)

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

JRS

  • Guest
Re: Newbie Question ..
« Reply #1 on: June 04, 2014, 10:54:39 AM »
Welcome Rob!

Wine isn't a bad option under Linux as Mike and Charles will attest. You can pretty much use any Windows DLL under Wine if the API you need isn't provided. O2 runs great under Wine.


Charles Pegge

  • Guest
Re: Newbie Question ..
« Reply #2 on: June 04, 2014, 12:17:47 PM »
Hi Rob, welcome to our forum.

Those 'a' thingys are generated by the GNU tools that FB uses for its back-end. I think they are static library headers, for the linker to use.

O2 native Linux development is rather slow, due to my lack of familiarity with this platform, and all the other items that require attention. How easy is it to bind dlls to your LISP systems? It would not be too difficult to put some opengl functions together for 3d viewing. Peter has already produced one for 2d graphics. This would enable you to continue in Windows and avoid relying on arcane 1980s graphics :)

RobbeK

  • Guest
Re: Newbie Question ..
« Reply #3 on: June 05, 2014, 12:32:49 PM »
Thank you , John & Charles ..

.. I wrote the input GUI calling the Java VM (not sure (i doubt) this can be run under Wine).
(and one important output call image->canvas - works extremely fast ), I'm somewhat forced to keep the schism between Win and Linux sofar (unless Wine will accept those Java calls )  .. the reason setting up these graphic buffer is that the JAR I use not even has an instruction for set/get a pixel (also the Java guiserver in NewLisp lacks this -- probably it is far too slow for such things , and the other thing was that Lisp has no flat memory arrays ..
Linux ..  I recompiled the FB math lib and there were 5-6 syntax errors in the official source !
The NewLisp (under  Linux)  in its REPL running in the terminal , and even when starting a script from the in-stream crashes on every number with a decimal point in it !!!!
0.0 ->  "0"  nil nil   (nil = the null character in other languages) ... 

Luckily this is a scripting language and Lisp :
@ the start

(define ( , (symbol .))    ;; defining another symbol for the dot
.
.
code with things 0,0 etc ...  (and a routine to fix the periods read from the input-stream)
.
.

(define (. (symbol ,))  ;; restoring the original (not strictly needed as the program ends here anyway)
end
 
it works , but it remains patchwork ..
The "new" Lisps like NewLisp and PicoLisp are both scripting languages , and both authors wrote very interesting about the pro's and cons compared with compilers (native or bytecode).
Benchmarking is not the main important criterium for a language choice --  but the CLisp that NASA used in the 1990's is in interpreted mode about 10x slower than a NewLisp script  --NewLisp + O2 is an enormous tool imho -- speed and a functional language (with macro's that easily sets up lazy evaluations etc ...  )
(not forgetting, Lisp is variadic by nature -- extremely handy for coding ,  most of the time in a function I just add some arguments while the program is growing (I told Lisp what to do with these  -- i don't have to add/change anything on the definition body !! ) , I do not have to know on forehand how many exactly are needed ;-)

some reading from Mr Burger (i think) :  4th paragraph :
http://picolisp.com/5000/-2-7.html?*ID=$login
(my idea is :   take best and use both )

best Rob
« Last Edit: June 05, 2014, 12:41:30 PM by RobbeK »

JRS

  • Guest
Re: Newbie Question ..
« Reply #4 on: June 05, 2014, 01:24:16 PM »
Hi Rob,

Take a peek at the \projectsB\Japi forlder of the O2 WIP zip. The Script BASIC JAPI extension module embeds the JAR with the Java code as a binary stream and is instantiated by JRE. Check out the http://www.japi.de/ abandoned project site for code and more info how to embed Java resources into your C or O2 programs.

John

RobbeK

  • Guest
Re: Newbie Question ..
« Reply #5 on: June 05, 2014, 02:59:29 PM »
Hi John,

I stand corrected ..  no problem at all calling the JVM, combined with the DLL's under Wine.

Lisp running under Wine, O2 DLL managing a flat memory model (fmemory.dll) and a little program reading the Japi.h headers and converted them readable for the Lisp FFI.
attached -- a screencopy with a fragment of the script .
.. I have to thank you , I gave up after one try (resulting in a (iirc 4711 error) when calling a JAR file under Wine ).

best Rob

.

JRS

  • Guest
Re: Newbie Question ..
« Reply #6 on: June 05, 2014, 03:03:25 PM »
Sweet!

Mike Lobanovsky

  • Guest
Re: Newbie Question ..
« Reply #7 on: June 05, 2014, 05:39:28 PM »
Linux GUI or GUI Linux rulez!

P.S. Otherwise ...

Aurel

  • Guest
Re: Newbie Question ..
« Reply #8 on: June 05, 2014, 08:57:13 PM »
....sucks. ... ;D

Charles Pegge

  • Guest
Re: Newbie Question ..
« Reply #9 on: June 06, 2014, 01:30:13 PM »
Rob,

How do you represent structures in Lisp? Are there any formal mechanisms, or do you have to build your own systems?

RobbeK

  • Guest
Re: Newbie Question ..
« Reply #10 on: June 06, 2014, 03:39:48 PM »
Hi , Aurel , Mike ..  well, even the desktop is not crash-proof (some recent experience) ...    :(

Charles, it's not strictly needed - the "list" mixes all possible types and may be nested with other lists -- the type is discovered by its syntax ,
p.e.    x is an integer /   x.y is a float  /   x/y a fraction  /   x+iy a complex number / "xyzab" a string /   \xyz  a char/byte /  nil is the nothing /  (whatever )  is a list /   'x  a symbol ... etc ,
.. lists an atoms of any type can be nested ,  to visualize nesting, maybe an example is thinking about describing the structure of a building - you open a door and there's a room , in that room there is a door , or maybe two or more doors etc..   the lists are a handy system to set-up bin trees without a pre-defined "branching" structure. 

As for the structures, it is best to make the code readable by simulating some structure like syntax (imo)  -- Lisp becomes very easy unreadable.

Let's say we're going to work with complex numbers :

(define (C# x y) (list x y))     ---   seems very idiotic, but we know now that (C# . . ) represents a complex number.

Now we can build.

(define (C+ a b &rest)  (list (+ (a 0) (b 0)) (+  (a 1) (b 1)) &rest ) )

now we can do something as (C+ (C# 4 3) (C# 1 3)) 
or better readable  :    (set 'z (C# x y))     and then  (C+ z z) etc..

-- that's not special, but - a moment we get the idea to add the polar coordinates to the system (we need the Euler/De Movre notation).

we can just expand  to the list      ->   ( x y r theta)  , the nice thing is that this new form is still valuable for our previous defined C+.

to test if it is an "extended" complex number :
(define (demoivre? Z)  (= (length Z) 4))

and if needed (define (expand-to-polar Z)  (when (not (demoivre? z)) (make-demoivre Z))) 

Summarizing :  languages as Basic are much better readable ;-)


-------------------------------  math stuff (probably boring)
A few weeks ago , I tried to set up an analytic formula for Fibonacci numbers ,  (I let the Lisp do it)  it went  :
the most important first , as the arguments are two numbers :
(a b) -> (b a+b)

(define (Fibnext n)  (list (n 1) (+ (n 0) (n 1))))
and then the iterations       (define unit (list 1 1))  -- the starting pair.   (doing all this by pairs is much more clearer //  pair->pair is much more logical than pair->number )
the code calculated the increase / iteration (it rapidly goes to (1+sqrt(5))/2     (the golden ratio btw)
then it calculated the initial constant in the formula , and checked the error against exact calculated values.

the obtained formula A+ C*pow((1+sqrt(5)/2),n) is "almost" exact.
to be honest - the Frenchman Bonnet calculated this exact around 1850/ and published it , but he needed 3 powers to do so (what is the minimum to do it exact)  -- and De Moivre found this +- a century before him, but found it not worth publishing ;-)
-------------------------------
Haskell introduced again the assignment declarations btw ..   it's sometimes somewhat difficult in Lisp -- NewLisp has separate commands for floats and ints + - * / and    add sub mul div   - and picoLisp works with unlimited bignumbers and a scaling factor for the floating point   , something as 132 scale 2 = 1.32   , Racket uses exact->inexact combined with broken numbers   ..  1/7 is an exact number, writing it decimal will take till the end of times , so it has to be converted into an inexact number ...    (and it also gives the possibility to works with streams like Haskell does (in-range) , (in-naturals) etc..   the lists are not pre-built but lazy calculated ...

summarizing : in a list everything can be mixed , even lists ( where ...    recursive ) ....

best Rob



 
« Last Edit: June 06, 2014, 10:08:57 PM by RobbeK »

JRS

  • Guest
Re: Newbie Question ..
« Reply #11 on: June 07, 2014, 11:24:07 AM »
One of Script BASIC's strong points beside being typeless is the free form matrix structures you can build with auto indirection. (practically unlimited definition and structures) Upper / lower bounds checking per index is is also support.

Code: [Select]
a[0]{""} = 0
a[0]{"0"} = "zero"
a[1]{""} = 1
a[1]{"1"} = "one"
a[2]{""} = 2
a[2]{"2"} = "two"

REF b = a

b[3]{""} = 3
b[3]{"3"} = "three"

PRINT a[3]{""},"\n"
PRINT a[3]{"3"},"\n"

 jrs@laptop:~/sb/sb22/test$ scriba testref.sb
3
three
jrs@laptop:~/sb/sb22/test$

RobbeK

  • Guest
Re: Newbie Question ..
« Reply #12 on: June 08, 2014, 02:51:00 AM »
Ah, nice !!

I think in the end most programming languages take up the good ideas of others  (or start a kind of symbiotic environment from scratch - maybe Python is a good example).
Lisp also evaluates this way -- the newer ones have much better iteration mechanisms than previous ones.
However one has to be careful by reason of the typeless nature of Lisp.
p.e.  (in the most simple form without break conditions )

(dotimes (i x )   ....  )  i :: integer
(for (i start end   )  ... )   i :: integer
(for (i start end step ) ....  )  i :: float   even when      (for (x 1 10 2) ...    )   x :: float
..  bravely Mr Lutz Mueller (NewLisp) introduced a general iteration variable $idx during the process - handy , but not sure how the Lisp community reacts.  (probably the least friendly comm. of them all - it seems they want to keep the language esoteric and they specialize in humilating newcomers   ???)

best Rob 

Mike Lobanovsky

  • Guest
Re: Newbie Question ..
« Reply #13 on: June 08, 2014, 03:09:28 AM »
... they specialize in humilating newcomers  ??? ...

Hi Rob,

If it ever happens to you, just tell John or me. We will go there and tear them to pieces.

:D

Charles Pegge

  • Guest
Re: Newbie Question ..
« Reply #14 on: June 14, 2014, 05:35:50 AM »

Hi Rob,

Many thanks for your LISP information. I am most interested in the computational properties of LISP, and wonder how this diametrically opposite language may be integrated with basic - possibly leaving all the hardcore to Basic and just dealing with abstract material.