Oxygen Basic

Information => Open Forum => Topic started by: RobbeK on June 04, 2014, 10:19:25 AM

Title: Newbie Question ..
Post by: RobbeK 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)

--------------------------------
Title: Re: Newbie Question ..
Post by: JRS 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.

Title: Re: Newbie Question ..
Post by: Charles Pegge 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 :)
Title: Re: Newbie Question ..
Post by: RobbeK 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
Title: Re: Newbie Question ..
Post by: JRS 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
Title: Re: Newbie Question ..
Post by: RobbeK 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

.
Title: Re: Newbie Question ..
Post by: JRS on June 05, 2014, 03:03:25 PM
Sweet!
Title: Re: Newbie Question ..
Post by: Mike Lobanovsky on June 05, 2014, 05:39:28 PM
Linux GUI or GUI Linux rulez!

P.S. Otherwise ...
Title: Re: Newbie Question ..
Post by: Aurel on June 05, 2014, 08:57:13 PM
....sucks. ... ;D
Title: Re: Newbie Question ..
Post by: Charles Pegge 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?
Title: Re: Newbie Question ..
Post by: RobbeK 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



 
Title: Re: Newbie Question ..
Post by: JRS 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$
Title: Re: Newbie Question ..
Post by: RobbeK 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 
Title: Re: Newbie Question ..
Post by: Mike Lobanovsky 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
Title: Re: Newbie Question ..
Post by: Charles Pegge 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.
Title: Re: Newbie Question ..
Post by: JRS on June 14, 2014, 11:49:46 AM
Quote from: Mike
If it ever happens to you, just tell John or me. We will go there and tear them to pieces.


(http://www.bedlingtontownfc.co.uk/images/BTFC_Bulldogs_Logo_New.png)
Title: Re: Newbie Question ..
Post by: Mike Lobanovsky on June 14, 2014, 01:38:07 PM
... this diametrically opposite language ...

Hehe,

Up till now I thought "esoteric" would be the mildest term to apply here but Charles certainly beats me to it with his "diametrically opposite language". Oh those Brits...  :D

May I suggest "perpendicular"? :D
Title: Re: Newbie Question ..
Post by: Charles Pegge on June 14, 2014, 02:25:06 PM
Perplexiculiar ? :)

Lisp may be strange to us because it is not within the Fortran lineage. But the syntax is absurdly simple:

A Lisp expression:

(    operator      zero or more operands ...    )

A Lisp operand can be a number, a quote or a name or another expression.

Title: Re: Newbie Question ..
Post by: Mike Lobanovsky on June 14, 2014, 02:53:59 PM
Perplexiculiar ? :)

(http://www.cms2cms.com/wp-content/uploads/2013/11/thumbs-up-256x256.png)


Pervexiculiar.

8)
Title: Re: Newbie Question ..
Post by: Charles Pegge on June 14, 2014, 10:42:54 PM
Actually, some block-structure makes a huge difference to readability:

Example: a multidimensional hypoteneuse:

  ( let hypot "
    ( sqrt
      ( + (next) ( * item item ) )
    )
  ")

  ( hypot 3 4 )  ;5
  ( hypot 1 3 5 1 ) ;6
Title: Re: Newbie Question ..
Post by: Mike Lobanovsky on June 15, 2014, 03:41:32 AM
Hmmmm Charles,

Is (next) a formal indication that the hypot macro is a "variadic loop" (don't know how to better put it)?

I'm a little scared to imagine what the Toy interpreter would look like if ported to Lisp...
Title: Re: Newbie Question ..
Post by: Charles Pegge on June 15, 2014, 04:11:45 AM
I have one brewing :)

(next) pulls an  "item" out of the parameter buffer, or terminates the iteration when the buffer is empty.

This is not Common-Lisp, I hasten to add

A simpler 2d hypot looks like this


  ( let hypot "x y
    ( sqrt
      ( + ( * x x ) ( * y y ) )
    )
  ")
Title: Re: Newbie Question ..
Post by: RobbeK on June 15, 2014, 05:54:22 AM
Hi all,

Thanks John , Mike  --  I feel safer now, consequently I will make a lot of trouble next time when there  ;)

The classic variadics :
 
(define (foo)
  (doargs (i) (print i " ")))

(foo 1 2 3) -> 1 2 3

(define (foo L)
 (dolist (i L) (print i " ")))

(foo (list 1 2 3)) -> 1 2 3

(map print (list 1 2 3))  -> 123    (no spaces, to fix this an anonymous function is needed)

(map (lambda(x) (print x " ")) (list 1 2 3)) -> 1 2 3

the glorious currying function !!!

(map (curry print " ") (list 1 2 3))  -> 1 2 3

the manual says : curry :::  Returns a function which will call FUNCTION passing it INITIAL-ARGS and then any other args. (funcall (curry #'list 1) 2) ==> (list 1 2)  .. iirc Mr Curry was a math professor (not sure)  .. in math language  (curry f(x,y,...)) = fx(y,....)

Doing sequential things variadic

(apply + (list 1 2 3))  -> 6

works of course for own written definitions :

 

like in :

(define (prime? x)
  (= 1 (length (factor x))))

(map prime? (list 1 2 3)) -> (nil true true)

so: setting up a boolean hash table for some primes :

(define prime-hash-index  (map prime? (sequence 1 100000)))   -- that's all   :-*

But all this magic is orthogonal on anything a processor understands and for this reason (mainly , there are some technical reasons making (for me) interpreted Lisp more interesting than compiled), the combinations with a compiler like O2,C whatever can be super additive .

As an example something I was curious about -- an extended Fibonacci -
While Fib considered the mapping (a b) -> (a a+b) , I expanded it to (a b) -> (a f(a,b))
In the program you can see one of the powertools (eval-script ... ) ; the math part is nothing (lines on NextFib) )
I should have written it variadic , but it will take less than a minute to convert to program for complex Fib numbers, or even Fib numbers of any dimension.

(ps the stories like that the Steel Bank Common Lisp compiler for common Lisp and the mysterious STALIN compiler for Scheme outperform C is imho wishful thinking --   use and a compiler and an interpreter , that's real power !! )

best Rob


oops , forgot : the mapping ->(b  (a+b)/n)  for n > 0

n < 2  ::-> inf
n=2 ::-> 2/3
n>2 ::->0

n=1 the classic Fib numbers


.
Title: Re: Newbie Question ..
Post by: Mike Lobanovsky on June 15, 2014, 06:24:47 AM
@Charles:

Quote
(    operator      zero or more operands ...    )
.........................
I have one brewing :)

If my memory doesn't slip me, long long ago when there was no OxygenBasic yet, your original assembler used to employ polish notation that may still be buried in the depths of O2H now in the form of some sort of an IDL. Isn't that why you're so fascinated with the possibilities of Lisp? :)

@Rob:

New Lisp seems to employ lots of parentheses in the user code. Does your editor highlight matching parentheses for you?
Title: Re: Newbie Question ..
Post by: RobbeK on June 15, 2014, 07:18:28 AM
Hi Mike,

The one I like the most is http://www.daansystems.com/lispide/    (matching parantheses highlighting + syntax colouring (NewLisp, Common Lisp  and some others ).
NewLispEdit is good, but on my computer things may getting slow (after a few hundred lines of source)  - it runs interpreted in NewLisp and uses the Swing Java guiserver ).
There's also ZionEdit , it does the matching paranth. , but the syntax colouring is Common Lisp not NewLisp.
There's Geany , I think it's possible to include the a list with NewLisp commands for highlighting purposes, matching paranth. on board and you can set up commands for make/build/run -- CLisp syntax is already included, NewLisp not.
For CLisp there was VisualCLisp (someone in Poland iirc) , it's gone however still downloadable with the Wayback Machine ..
(CLisp imho still is interesting - very good FFI doing both cdecl and stdc -- floats upto over 3000 digits - Unlimited Length Integers , consequently slow (soft floats) ,  interpreted and compiled mode (bytecode + GNU lightning JIT ).  It comes with a primitive REPL (from the command line, running in a Terminal) - I wrote the necessary Japi bindings and an O² DLL making it possible to access flat memory  (if someone wants these, just ask ).
Probably Eclipse etc.. has plug-ins to do so, but I do not like mega-systems  ...
There's also Emacs , but again I'm too lazy to learn it ... (it's too much)
There's Lisp in a box , LispBox and LispStick with complete environments , but see the line(s) above ...
There are things for Visual Studio,  but ... 

best Rob
Title: Re: Newbie Question ..
Post by: Mike Lobanovsky on June 15, 2014, 07:53:08 AM
Hi Rob,

The choice looks impressive.

Quote
on my computer things may getting slow (after a few hundred lines of source)

May happen if it's based on a standard richedit control with syntax highlighting implemented as continuous on-the-fly translation of plain text to the native rich text format. Not the best solution for a professional IDE IMHO.

Thanks for the feedback anyway. :)
Title: Re: Newbie Question ..
Post by: Aurel on June 15, 2014, 11:00:50 AM
Hmm Lisp....  ;D

.
Title: Re: Newbie Question ..
Post by: JRS on June 15, 2014, 11:23:42 AM
Sorry that you can't understand me, I'm disabled and speak with a lisp impediment.  ;D
Title: Re: Newbie Question ..
Post by: Charles Pegge on June 16, 2014, 03:43:05 AM
Hi Mike,

I created an interpreted  reverse-polish language called R$ which may be still around on Josés forum. RP languages are okay for writing, but trying to read them back boggles the mind :)

Attempting to represent types, and cleanly interface DLLs also breaks the minimalist principles of such languages.



Rob,

This is how I would implement an average function:

Code: [Select]
( let average "
  ( eval
    ( let n 0 )
    ( /
      ( +
        (next) (incr n)
        item
      )
      n
    )
  )
")

( average 1 2 3 4 5 ) (cr) ;3

hmm .. that's five levels of brackets!

A more complex example: building a list of primes:

Code: [Select]
( let primes " c
  ( eval
    ( let p '1 2 3' )
    ( let v 4     )
    ( let n 2     )
    ( let d )
    ( eval
      ( set n 2 )
      ( loop ( eval
        ( set d ( getmid p n 1 ) )
        ( if d
          ( )
          ( eval
            ( setmid p 0 0 v )
            (exit)
          )
        )
        ( if ( == 0 ( mod v d ) )
          ( eval
            (exit)
          )
        )
        ( incr n )
      ) )
      ( incr v )
      ( iter c )
    )
  p
  )
")
( primes 50 ) (cr) ; 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53

John,

In some old texts, (I have an 1830s Bible like this) the lowercase 's' is almost identical to 'f'.

It lookf very ftrange when you fee it

Title: Re: Newbie Question ..
Post by: Mike Lobanovsky on June 16, 2014, 04:05:22 AM
I'm disabled and speak with a lisp impediment.  ;D

Hehe,

Come to think of it, "lisp" certainly isn't an euphonic name for a language. If I understand correctly, "lisp" is an impediment when someone would speak as if he had his front teeth knocked out.

:)

(Charles: something's telling me that Malleus Maleficarum would be a better treatise to look for the sources and occurences of this impediment)
Title: Re: Newbie Question ..
Post by: RobbeK on June 16, 2014, 06:32:35 AM
Looking very interesting Charles --  the usual way (NewLisp syntax)

=================================



(define (mean L)
  (div (apply add L) (length L)))

(define (another-mean L)
  (div (eval (cons 'add L )) (lenght L)))

;;the usual way but bad examples --  + already is variadic , for non-variadic functions only the first element is processed and returned.

(define (meanO)
 (let ((m 0) (n 0))           ;; let defines the locals (parallel)  let*/letn sequential
  (doargs (i)
     (inc m i)
     (inc n))
 (div m n)))                   ;; result must be returned within the (let     ....  ) 
               
;;  (meanO 5 6 7) -> 6  :: using arg(i)   

(define (meanOO L)
  (apply meanO L))
;; works on a List now   (meanOO (list 5 6 7) )


;; by Iteration

(define (meanI L)
 (let ((m 0)  (n (length L)) )
  (dotimes (i n)
     (inc m (L i)) )
  (div m n)))

;; using the direct index i (0...n-1)   ::  in Common Lisp (L i) is written  (nth i L) 

(I use a wider font for Lisp  ::) than shown here ...     something as doargs could be very useful .
Common Lisp uses also &rest

(defun something (a b &rest r)  r )

(something '( 1 2 3 4 5)) -> (3 4 5)

Hi Mike,

" as if he had his front teeth knocked out."   ..  but, but , that's the greenhorn treatment at your first Lisp Congress, how did you know ??
 ;)

best Rob




Title: Re: Newbie Question ..
Post by: Mike Lobanovsky on June 16, 2014, 07:50:54 AM
... that's the greenhorn treatment at your first Lisp Congress ...

Hehe,

The Lisp community is trying to live up to its name. :D