Author Topic: Lisp in Basic  (Read 208286 times)

0 Members and 2 Guests are viewing this topic.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #690 on: August 23, 2014, 12:39:11 PM »
Mehdi added the following math and trig functions to FBSL:

Code: [Select]
// Conversion d'angles degrés <-> radians
{"degrees", r2d},
{"r2d", r2d},
{"radians", d2r},
{"d2r", d2r},

// Fonctions trigonométriques (versions radians = normal)
{"cos", cos},
{"cosec", cosec},
{"cotan", cotan},
{"sec", sec},
{"sin", sin},
{"tan", tan},

{"acos", acos},
{"acosec", acosec},
{"acotan", acotan},
{"asec", asec},
{"asin", asin},
{"atan", atan},

{"cosh", cosh},
{"cosech", cosech},
{"cotanh", cotanh},
{"sech", sech},
{"sinh", sinh},
{"tanh", tanh},

{"acosh", __acosh},
{"acosech", acosech},
{"acotanh", acotanh},
{"asech", asech},
{"asinh", __asinh},
{"atanh", __atanh},

// Autres notations (~VB) :
{"atn", atan},
{"cosin", cos},
{"sinus", sin},
{"tgn", tan},

{"arccos", acos},
{"arccosec", acosec},
{"arccotan", acotan},
{"arcsec", asec},
{"arcsin", asin},
{"arctan", atan},

{"hcos", cosh},
{"hcosec", cosech},
{"hcotan", cotanh},
{"hsec", sech},
{"hsin", sinh},
{"htan", tanh},

{"harccos", __acosh},
{"harccosec", acosech},
{"harccotan", acotanh},
{"harcsec", asech},
{"harcsin", __asinh},
{"harctan", __atanh},

// Version degrés (pas toutes) :
{"cosd", cosd},
{"cosecd", cosecd},
{"cotand", cotand},
{"secd", secd},
{"sind", sind},
{"tand", tand},

{"acosd", acosd},
{"asind", asind},
{"atand", atand},

// Autres notations (degrés) :
{"arccosd", acosd},
{"arcsind", asind},
{"arctand", atand},

// Notations V2 :
{"ctnd", cotand},
{"secd", secd},
{"cscd", cosecd},

// Fonctions de racines et puissances
{"sqrt", sqrt},
{"sqr", sqrt},
{"cbrt", __cbrt},
{"cbr", __cbrt},
{"square", square},
// voir aussi xrt, nrt, pow dans dbl_two


// Fonctions exponentielles et logarithmes
{"exp2", __exp2},
{"expm1", __expm1},
{"exp", exp},

{"ln", log},
{"log", log},
{"log10", log10},
{"log1p", __log1p},
{"log2", __log2},
{"logb", logb},
// voir aussi logx, logn dans dbl_two

// Fonctions d'arrondi
{"round", round},
{"ceil", ceil},
{"floor", floor},
{"nearbyint", nearbyint},

// Valeur absolue
{"abs", fabs},
{"fabs", fabs},

// Fonctions d'erreur
{"erf", erf},
{"erfc", erfc},

// Fonctions diverses
{"lgamma", lgamma}

// Autres
{"rnd", rnd}
{"rand", rand}
{"randint", randint}

{"atan2", atan2},
{"atn2", atan2},
{"arctan2", atan2},

{"logx", logx},
{"logn", logx},

{"xrt", xrt},
{"nrt", xrt},

{"pow", pow}
{"gcd", gcd}, // PGCD
{"scm", scm}, // PPCM

not counting approx. 30 math constants.

Mike enriched them with the following:

Code: [Select]
__f1("sgn", Sgn, 1),
__f1("min", MiN, 2),
__f1("max", MaX, 2),
__f1("min3", MiN3, 3),
__f1("max3", MaX3, 3)

and also added a layer of 150 single-precision vector and square matrix functions.


Now what?

JRS

  • Guest
Re: Lisp in Basic
« Reply #691 on: August 23, 2014, 12:58:50 PM »
Quote
Now what?

I would say Rob has a wealth of MATH functions at his disposal in BL. (SB min set / FBSL full extended math library)


Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #692 on: August 23, 2014, 01:04:49 PM »
IMO the additions I suggested coupled with what's already in BL would make a perfect basis for most common everyday calculations. Everything extra should come from a math library/extension at a later stage.

We aren't planning intensive math calc in BL right now, are we?

JRS

  • Guest
Re: Lisp in Basic
« Reply #693 on: August 23, 2014, 01:11:17 PM »
Quote
We aren't planning intensive math calc in BL at this stage, are we?

Good point.

Just to make sure we are all on the same page, the ongoing goals as I understand them are as follows.

  • Eliminate GOSUB/GOTO and stabilize the existing code.
  • Provide Rob with obvious missing functionality (iterator, std math, ...) in the prototype form.
  • Freeze the BL source and formulate a C migration plan so BL is callable from BASIC.
  • Incorporate new features Rob or Arthur might suggest.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #694 on: August 23, 2014, 01:13:00 PM »
Generally, yes.

I'm writing a short report with my findings on the usability of Lisp-in-Basic code for the needs of SB, O2, and FBSL. I have tried many things, and I have failed many times. I want to discuss with you my vision of what we can do based on my trial and error.

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #695 on: August 23, 2014, 01:14:48 PM »
Hi John , Mike

Finished something (doesn't crash - draws - needs fine-tuning ) post it tomorrow after testing ...

One more time  ;)  the importance of iteration -- in Lisp , things are assigned parallel   like (let .... ) etc ...  this makes things possible as
(define a '(a b))
(set! a (list (car (cdr a)) (car a)))
-> (b a)
a swap without declaring a temp. variable

this is a good example from the code :

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

(define sq (lambda(x) (* x x)))
 
(define level
   (lambda (it x y rc ic orb)
      (if (or (= it 0) (> orb 4)) it
          (level (- it 1) (+ rc (- (sq x) (sq y)))
                 (+ ic (* 2 x y)) rc ic (+ (sq x) (sq y))))))
-----------------------

the nucleus of the program !  it calculates the orbit and gives back how many iterations were needed to reach the condition more than 4 or a max of iterations -- but this is no iteration, this is recursion - which means the parameters are bound parallel, which means that the calculation of the orbit (+ (sq x) (sq y)) uses the old values of  x and y and not the new calculated ones, for this reason I should have to calculate them once again - or set up local variables every recursion cycle.
Remark the difference with NewLisp , any CL , and probably any other Scheme :

(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 )))
-----
assigned in sequence --

Is it possible to add any (no mather what ever) iterative , looping mechanism ???

best Rob



 


JRS

  • Guest
Re: Lisp in Basic
« Reply #696 on: August 23, 2014, 01:17:59 PM »
Quote
I'm writing a short report with my findings on the usability of Lisp-in-Basic code for the needs of SB, O2, and FBSL. I have tried many things, and I have failed many times. I want to discuss with you my vision of what we can do based on my trial and error.

Can we do this on the AllBASIC IRC instead? I promise it will result in a more productive use of our time and with a better understanding of the issues. I can attach a copy of the IRC session log for others not directly involved.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #697 on: August 23, 2014, 01:39:03 PM »
I'm curious why Rob is almost never responding to the subject of others' messages?

I am not going to add any loops until he shows me definitely and unequivocally a Scheme in which such loops are present by definition. I am not going to add any more math and trig functions until he gives me the exact formulation of their syntax. I do not want to breed lexicographical bastards in the initially pure Schem-atic environment of BL without the exact reason why I should do just this. I am not a LISP programmer and I need motivated guidance which Rob so far denies to offer.

BL is currently written as Scheme-in-Basic, not as Common-Lisp-in-Basic. Are we going to re-write it as Common Lisp or should we keep it as Scheme?

I would be greatful to hear John's and Rob's responses to this question. I would also appreciate Charles' opinion on that if possible.
« Last Edit: August 23, 2014, 04:38:51 PM by Mike Lobanovsky »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #698 on: August 23, 2014, 01:43:42 PM »
Can we do this on the AllBASIC IRC instead?

Only if Rob is there and takes active part in the conversation. If not, we can simply continue here as we always did. Don't see any reason why this thread can't be as effective as an IRC. We're talking business, after all.

JRS

  • Guest
Re: Lisp in Basic
« Reply #699 on: August 23, 2014, 01:53:07 PM »
The best way to use the IRC is get a good IRC client, connect to the AllBASIC channel and forget about it. The IRC client will notifiy you of activity. You will be amazed how much can be accomplished in a focused chat session. This is the last I'm going to say about this. I'm always there and happy to discuss BASIC topics of value.


Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #700 on: August 23, 2014, 01:56:47 PM »
Rob,

Quote
Remark the difference with NewLisp , any CL , and probably any other Scheme

SCHEME is the key word in this sentence! I am not asking about NewLisp or CL. I need to see at least one SCHEME that does just that with my own eyes, not "probably" and not "any other", but one particular Scheme and now.

Can you do that for me, please?

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #701 on: August 23, 2014, 02:11:13 PM »
John, we are flooding the thread with irrelevant things piled on top of our immediate issues. It is becoming difficult to attract the attention of the addressee when meaningful messages are diluted with irrelevant propaganda and counter-propaganda.

Let's keep our country clean. I need answers from Rob and I don't want to listen to anything else.

I have spent a week of my life on this project and I think I'm entitled to hear answers to the questions I've been posting here a dozen times again. I will not stir a finger until I have them answered:

1. Show me the Scheme that has looping in it. I want to see its commands and their syntax.

2. I will add the looping only based on what I will see in at least one such Scheme available on the net.

3. Give me the Scheme names and syntax for (tan), (cotan), (sqrt), (pow) and (mod) and I will immediately add them to BL.


Is it so difficult just to spend 30 seconds and give me what I need? I am not asking out of sheer curiosity; I am currently the developer of this project and everything new in it comes from under my fingers. I must know what I should do before I waste yet another week for nothing.

Thanks much everyone for their attention.



[UPD] All questions answered. John and Rob, thank you for your valuable feedback!
« Last Edit: August 24, 2014, 01:01:44 AM by Mike Lobanovsky »

JRS

  • Guest
Re: Lisp in Basic
« Reply #702 on: August 23, 2014, 02:18:41 PM »
Sounds like a good plan to me. Let me know if there is anything I can do.

http://en.wikibooks.org/wiki/Scheme_Programming/Further_Maths

This Scheme code from WikiBooks doesn't seem to complain.

Code: [Select]
;;; finding if an element exists in that list                           
                                                                         
; (define exists-in?                                                     
;   (lambda (ele lis)                                                   
;     (cond ((null? lis) #f)                                             
;           ((equal? ele (car lis)) #t)                                 
;           (else (exists-in? ele (cdr lis)))                           
;     )                                                                 
;   )                                                                   
; )                                                                     
                                                                         
;;; 'mapping' each element of the list to some value                     
                                                                         
(define plustwo                                                         
  (lambda (lis)                                                         
    (cond ((null? lis) nil)                                             
          (else (cons (+ (car lis) 2)                                   
                      (plustwo (cdr lis)))                               
          )                                                             
    )                                                                   
  )                                                                     
)                                                                       
                                                                         
;;; 'fold up' a list of such values into a single value                 
                                                                         
(define foldr                                                           
  (lambda (f e lis)                                                     
    (cond ((null? lis) e)                                               
          (else (f (car lis) (foldr f e (cdr lis))))                     
    )                                                                   
  )                                                                     
)                                                                       
                                                                         
;;; use this folding function to define a function called any           
                                                                         
(define any                                                             
  (lambda (pred lis)                                                     
    (foldr (lambda (x acc) (or x acc))                                   
           #f                                                           
           (map pred lis)                                               
    )                                                                   
  )                                                                     
)                                                                       
                                                                         
;;; Using this function we can re-write exists-in?                       
                                                                         
(define exists-in?                                                       
  (lambda (ele lis)                                                     
    (any (lambda (x) (equal? x ele)) lis)                               
  )                                                                     
)                                                                       

jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb looptest.scm
SBLisp - Scheme BASIC Lisp

(define plustwo
  (lambda (lis)
    (cond ((null? lis) nil)
          (else (cons (+ (car lis) 2)
                      (plustwo (cdr lis)))
          )
    )
  )
)
PLUSTWO
(define foldr
  (lambda (f e lis)
    (cond ((null? lis) e)
          (else (f (car lis) (foldr f e (cdr lis))))
    )
  )
)
FOLDR
(define any
  (lambda (pred lis)
    (foldr (lambda (x acc) (or x acc))
           #f
           (map pred lis)
    )
  )
)
ANY
(define exists-in?
  (lambda (ele lis)
    (any (lambda (x) (equal? x ele)) lis)
  )
)
EXISTS-IN?
T
0](quit)
jrs@laptop:~/sb/sb22/sblisp$
« Last Edit: August 23, 2014, 02:47:32 PM by John »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #703 on: August 23, 2014, 02:47:50 PM »
Thanks a lot, John,

This is indeed very informative and helpful. I'm removing question 3 from the agenda.


I think
Code: [Select]
...........
    (foldr (lambda (x acc) (or x acc))
           #f           ; <== probably wrong and should BE (), which is BL's symbol for FALSE
           (map pred lis)
    )
.............
wouldn't be correct and would throw an exception at run time. In fact, you haven't changed the grammar for FALSE, you only made BL print F instead of () to the console. But BL wouldn't recognise F as a valid input for FALSE.
« Last Edit: August 23, 2014, 02:58:24 PM by Mike Lobanovsky »

JRS

  • Guest
Re: Lisp in Basic
« Reply #704 on: August 23, 2014, 03:04:35 PM »
 :-\  I had a bad feeling about changing that. Please put it back the way it was.