Author Topic: Lisp in Basic  (Read 208299 times)

0 Members and 3 Guests are viewing this topic.

JRS

  • Guest
Re: Lisp in Basic
« Reply #675 on: August 22, 2014, 02:43:14 PM »
Quote
please don't rush me.

Take all the time you need to do it right.

I was just going by the last info I had which was when I got up and was having coffee there would ba an update waiting. No fear, I was still able to carry on with the rest of my day.  ;)

Wow! Getting rid of BSD is something.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #676 on: August 22, 2014, 03:39:08 PM »
Wow! Getting rid of BSD is something.

It made the file ~700 lines shorter and faster because incrementation/decrementation is unnecessary. All BSD did was count the current recursion depth. Now the subs exit early automatically in response to an error flag until surfaced in the main loop where the flag is cleared.

All functions are turned back to subs as there's no need to assign error returns. This should also make the code run a bit faster.

Interactive sessions run OK but file execution still fails.

Now I'm going to have a break and grab some sleep. Hopefully I'll isolate the bug tomorrow morning with a cleaner head.

JRS

  • Guest
Re: Lisp in Basic
« Reply #677 on: August 22, 2014, 04:00:13 PM »
That sounds great. Looking forward to seeing it in action.

FYI - I gave up on the PBCC conversion after your warning of potential of a waste of time.

« Last Edit: August 22, 2014, 05:05:30 PM by John »

JRS

  • Guest
Re: Lisp in Basic
« Reply #678 on: August 22, 2014, 05:35:55 PM »
I would like to make another proposal.

Lets not call it XBlisp any longer and lets call it BASIC Lisp. (BL for short) Each BASIC involved in the project can integrate with it in their own way and on their terms. I'm happy with SBLisp (Scheme BASIC Lisp) and since it's a language of its own, the SB factor is under the covers just like C is under the covers for SB. When you run the SBLisp program, unless you knew it was written in SB, there is no reference to it. My goal is to get SBLisp as an extension module and interacting with SB. I'm not a Lisp programmer and learning from the other members of the project.

FYI - For those noticing site slowdowns, I hope we have it resolved. (China connections trying to use my server as a proxy to get around their oppressive government.)

O2 Forum Activity - 1 Year


« Last Edit: August 22, 2014, 09:50:20 PM by John »

JRS

  • Guest
Re: Lisp in Basic
« Reply #679 on: August 22, 2014, 10:35:37 PM »
Rob,

Are you able at this time to give us a usability evaluation of BASIC Lisp? I guess what I'm asking for is Arthur's Scheme Lisp a sub-set, a unique hybrid or something else? I want to try Scheme code I find but don't know if it's compatible with BL. I feel we are on to something with this if we can combine the best of Lisp and Basic in a seamless manor. I don't think Mike would be spending the time on this and using a rivals BASIC if he didn't see something of value. (for FBSL or any traditional BASIC compatible that follows QB rules)

 

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #680 on: August 23, 2014, 02:46:21 AM »
Hi John,

Quote
Lets not call it XBlisp any longer and lets call it BASIC Lisp.
Whatever as long as it isn't called SBLisp here. Sounds too confusing to me.

Quote
O2 Forum Activity - 1 Year
Haven't I brought along a couple of K's since registered? ;)

Quote
I don't think Mike would be spending the time on this and using a rivals BASIC...
We are neither rivals nor competitors. For me, SB is just another BASIC like O2 or thinBasic among those that can interest me to the extent of actually coding something in them.

I'm a veteran and I am just doing what I please. You may call it "fooling around". But once I lay my hands onto something, I feel obliged to bring it to the end. I looked through your SB code and saw it was inoperative, and then I re-translated the original into FBSL and it worked. I then saw a challenge in making the SB code work too and that's how I got hooked onto it. Then Oxygen was naturally added as long as we were on Charles' forum, and this is how I came to be where I am.

I don't have any special plans for LISP for FBSL; just thought it might be an entertaining optional addition to the three languages available in FBSL. I'm not a miser and I will be glad if it works out in the end and similar modules will appear in SB and O2 too.

Apart from that, there's no conspiracy or strategic aspirations in my BL activity. :)


P.S. I have fixed about three dozens bugs in my yesterday's code and now files are loaded correctly too. There is just one offending sub left -- SUB EvalSequence() -- that's called three times in other subs and that still breaks the natural program flow. The problem is it isn't really a sub but rather a simple loop that recurses deeper and deeper but it doesn't have a natural exit of its own. I have yet to invent a way to get it out of recursion all by itself before BL starts to function faultlessly. But again, I need some rest after almost 6 hours of tapping on my keyboard.

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #681 on: August 23, 2014, 03:00:20 AM »
all,    ...

Made a prototype for BL in NewLisp -- as this language is a kind of mix between Scheme and CL , the syntax is chosen very close to BL.  However, I do have to convert all the iterations now.
As this is about a 2D object - it will not be story of the "the nose , the pea & the mountain" , but  "the nose , two peas & a mountain "
OK - everything can be done by recursion , but it's a p in the a  (with a capital P here)

the code in iterative Lisp / Scheme is simple :

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

(define grid '())
(define nr 40)
(define mapped-grid '())
(define car (lambda (L) (L 0)))
(define cadr (lambda (L) (L 1)))

(define sq (lambda (x) (mul x x)))

(define level
   (lambda (L)
     (letn ( (x (car L)) (y (cadr L)) (rc x) (ic y) (it 11) (orb 0) (dp 0) (ret 0) )
       (dotimes (i it (> orb 4))
          (setq dp x)
          (setq ret i)
          (setq x (add rc (sub (sq x) (sq y))))
          (setq y (add ic (mul 2 dp y)))
          (setq orb (add (sq x) (sq y)))) ret )))

(define fill-grid
     (lambda (m)
       (setq grid '())
       (let ((xo -1.5) (yo -2.3) (dz (div 3 m)) (x 0) (y 0) (n (+ 1 m)) )
         (dotimes (i n)
           (setq x (add xo (mul i dz)))
           (dotimes (j n)
              (setq y (add yo (mul j dz)))
                (push (list y x) grid))))))


(define map-grid
    (lambda () (setq mapped-grid (map level (reverse grid)))))

(define print-grid
    (lambda ()
      (letn ((length-grid (length mapped-grid))  (nl (sqrt length-grid)))
        (dotimes (i length-grid)
         (let ((item (mapped-grid i)))
          (when (= 0 (mod i nl)) (println))
          (if (= 10 item)
                 (print item )
                 (print item " ")))))))

(define main
    (lambda ()
       (println "Levels of Mandelbrot - NewLisp")
       (println "------------------------------")
       (println)
       (let ((answer ""))
         (while (!= answer "q")
            (print "Give Width/height - [ q quits ] : ")
            (setq nr (read-line))
            (println)
            (fill-grid (int nr))
            (map-grid)
            (print-grid)
            (println)
            (println)
            (println)  ))))

(main)

--------------------------------------------------  an executable is attached   (try 32 or so)

best Rob
(John,  I'll answer after the coding experience this evening )
(Mike, is it possible at the level you're working on this code to add  only something as loop and exit-loop (from here everything can build to make a "practical" Scheme   )



.
« Last Edit: August 23, 2014, 03:17:09 AM by RobbeK »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #682 on: August 23, 2014, 05:02:15 AM »
Hi Rob, :)

This really looks nice but it doesn't seem to follow the BASIC and C originals that I posted earlier.

To make our conversation more precise and technical, can you please give me very brief and definitive answers to the following list of my questions? I'd like to see all the questions answered even if in the simplest form of "yes" or "no".

1. Are you able to write general LISP code (not for BL but for yourself) exclusively in Scheme? No NewLisp, no CL, no Bigloo, no anything but pure refined Scheme from the beginning of the program to its very end, even if you don't like Scheme personally?

2. If yes then exactly which Scheme package would you use for that? Can you give me a link to its documentation so that I could get acquainted with its base vocabulary (without libraries, includes, extensions, user-defined macros, etc.)?

3. Are there any iterators like for, do, loop, while, etc. in the vocabulary of Scheme package that you would use for your code as per Items 1 and 2 above?

4. You have designed iterate and iterate+ from the keywords available in BL's existing vocabulary. If the answer to Item 3 above is "yes", then can you design do and while too just like you designed your iterate and iterate+? (your arguments that it would be too slow or something will be ignored because speed doesn't really matter to us at this point)


I'm looking forward to your soonest reply.
« Last Edit: August 23, 2014, 05:33:43 AM by Mike Lobanovsky »

JRS

  • Guest
Re: Lisp in Basic
« Reply #683 on: August 23, 2014, 08:24:41 AM »
Heads-Up - The Bitbucket repository name (and link) have been change to reflect the new name for the project.

https://bitbucket.org/ScriptBasic/basic_lisp

Please update your shortcuts and bookmarks.


JRS

  • Guest
Re: Lisp in Basic
« Reply #684 on: August 23, 2014, 09:31:55 AM »
Quote from: Mike
Haven't I brought along a couple of K's since registered?

Just the Aurel catalyst effect has earned your salt.

I would also like to purpose that we start using the AllBASIC IRC more when we are working through a problem rather than flood the O2 forum. The forum should be used to post progress and query for ideas. I think the IRC is better for discussing problems and solutions.
« Last Edit: August 23, 2014, 10:26:27 AM by John »

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #685 on: August 23, 2014, 11:04:34 AM »
Hi Mike,

1) Yes -- but what is pure refined Scheme , next are the language specifications the : r5rs standard , you can find the iterator (do ....) belonging to the library syntax -- if some one should refuse these , you will also have to remove let let* "and" "or" cond .... etc etc http://www.schemers.org/Documents/Standards/R5RS/r5rs.pdf

2) Everything is here , but there is nothing that can build any iteration.  I mean things like the modulus is missing and also the squareroot  , but these are easy to define  (pe (define sqrt (lambda (x) (exp (/ (log x) 2))))  -- but no iteration can be defined without any primitive available -- only (do ..  ) is missing (it will build all other iterative constructions)

3) (do .. ) the most general , I only need one ..  remark that this Scheme has no "named let" either

4) iterate/iterate+ are recursive constructions poorly simulating iteration , and only on one level , they can not be nested because based on single recursion - I can write double-recursive mechanisms and call these iterate2 or something like.

I started converting the NewLisp code now -- and this is an example of building an xy space recursively

(define fill-grid
   (lambda (nrx xo dx nry yo dy matrix dup)
       (if (and (= 0 nrx) (= 0 nry)) matrix
         (if (= 0 nry) (fill-grid (1- nrx) xo dx dup yo dy matrix dup)
           (fill-grid nrx xo dx (1- nry) yo dy
            (cons (list (+ xo (* nrx dx)) (+ yo (* nry dy))) matrix) dup)))))

a recursive way to fill a list with 2D coordinates  (it works correctly) - it sets up a list of lists containing (x y)

I think there's something fundamental wrong with languages missing any iterative construction -- p.e. if the main function runs an infinite loop , there's no other way of calling itself to run ... a mechanism as (do .. ) will provide everything needed to overcome such bizar situations.

best , Rob
 

JRS

  • Guest
Re: Lisp in Basic
« Reply #686 on: August 23, 2014, 11:28:14 AM »
Rob,

Quote
I mean things like the modulus is missing and also the squareroot ...

Please don't waste your time with defining math functions. These are VERY easy to add to BL. (BASIC functions providing the juice)


RobbeK

  • Guest
Re: Lisp in Basic
« Reply #687 on: August 23, 2014, 12:12:54 PM »
Hi John,

Don't worry ,  just needed it because from a square grid z² , i need to put a newline after every z  (and that's sqrt(z²) ) (or specific the sqrt from the length that represents the list of xy coordinates  ::) -- i only define the things needed for the code.

-- just "lazy" definitions , I add them when needed ...

best Rob
(if it were possible the iterative (do ... ) could be included  ...  recursion is such a waste of memory , speed , etc ... )

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #688 on: August 23, 2014, 12:18:59 PM »
Quote
I mean things like the modulus is missing and also the squareroot ...
Please don't waste your time with defining math functions. These are VERY easy to add to BL. (BASIC functions providing the juice)

Rob,

Currently we have arith operators and also (sin), (cos), (atan), (exp), and (log).

I can also add the following procedures right away: (tan), (cotan), (sqrt), (mod), and (pow). If you want me to do it, please give me the exact names of these functions in LISP and the exact typical syntax how they should be written in a LISP program together with their operands.

Until then, please keep on using BL lambdas to emulate them if possible.

JRS

  • Guest
Re: Lisp in Basic
« Reply #689 on: August 23, 2014, 12:26:51 PM »
Tom added RAD and filled in the stubs in SB with the following functions. (SB 2.2 only)

Code: [Select]
' Given the starting value of 34 degrees, calculate radians.
' Given the radian value, calculate TAN, COTAN, SECANT and COSECANT.
' Given the TAN, COTAN, SECANT and COSECANT values,
' calculate the ATAN, ACTAN, ASECANT and ACOSECANT.
'
degval = 34
radval = RAD(degval)
zerval = 0

tanval = TAN(radval)
cotval = COTAN(radval)
secval = SECANT(radval)
cseval = COSECANT(radval)

ataval = ATAN(tanval)
actval = ACTAN(cotval)
aseval = ASECANT(secval)
acoval = ACOSECANT(cseval)

hsinv = HSIN(radval)
hcosv = HCOS(radval)
htanv = HTAN(radval)
hsecv = HSECANT(radval)
hcosc = HCOSECANT(radval)
hcotv = HCTAN(radval)

print "\nThe following 8 functions accept radians as their argument, so we "
print "use the\nnew RAD() function to convert ",degval," degrees to ",radval," (",str$(radval),") radians.\n\n"

print "Tangent\t\tCotangent\tSecant\t\tCosecant\n"
print "TAN()  \t\tCOTAN()  \tSECANT()    \tCOSECANT()\n"
print tanval," \t",cotval,"\t",secval," \t",cseval,"\n"
print str$(tanval)," \t",str$(cotval)," \t",str$(secval)," \t",str$(cseval),"\n\n"

print "Arctangent\tArccotangent\tArcsecant\tArccosecant\n"
print "ATAN()    \tACTAN()  \tASECANT()\tACOSECANT()\n"
print ataval," \t",actval," \t",aseval," \t",acoval,"\n"
print str$(ataval)," \t",str$(actval)," \t",str$(aseval)," \t",str$(acoval),"\n\n"

print "There are 6 Hyperbolic functions. They also accept radian arguments.\n\n"
print "H-Sine\t\tH-Cosine\tH-Tangent\n"
print "HSIN()\t\tHCOS()  \tHTAN()\n"
print hsinv," \t",hcosv," \t",htanv,"\n"
print str$(hsinv)," \t",str$(hcosv)," \t",str$(htanv),"\n\n"

print "H-Secant\tH-Cosecant\tH-Cotangent\n"
print "HSECANT()\tHCOSECANT()\tHCTAN()\n"
print hsecv," \t",hcosc," \t",hcotv,"\n"
print str$(hsecv)," \t",str$(hcosc)," \t",str$(hcotv),"\n\n"

Output

Code: [Select]
jrs@laptop:~/sb/sb22/test$ scriba testmath.sb

The following 8 functions accept radians as their argument, so we use the
new RAD() function to convert 34 degrees to 5.934119e-01 (0.593412) radians.

Tangent Cotangent Secant Cosecant
TAN()  COTAN()  SECANT()    COSECANT()
6.745085e-01 1.482561e+00 1.206218e+00 1.788292e+00
0.674509 1.482561 1.206218 1.788292

Arctangent Arccotangent Arcsecant Arccosecant
ATAN()    ACTAN()  ASECANT() ACOSECANT()
5.934119e-01 5.934119e-01 5.934119e-01 5.934119e-01
0.593412 0.593412 0.593412 0.593412

There are 6 Hyperbolic functions. They also accept radian arguments.

H-Sine H-Cosine H-Tangent
HSIN() HCOS()  HTAN()
6.288574e-01 1.181297e+00 5.323451e-01
0.628857 1.181297 0.532345

H-Secant H-Cosecant H-Cotangent
HSECANT() HCOSECANT() HCTAN()
8.465274e-01 1.590186e+00 1.878481e+00
0.846527 1.590186 1.878481

jrs@laptop:~/sb/sb22/test$

P.S. I have a cleaned up version of this somewhere using SB FORMAT().