Author Topic: Lisp in Basic  (Read 208047 times)

0 Members and 3 Guests are viewing this topic.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #105 on: August 04, 2014, 02:57:59 AM »
@Rob:

Thanks!

Lisp floor() is not correct! This isn't floor() (truncation towards integer), this is round() (arithmetic rounding)! I'm starting to dislike Lisp...


@Peter:

Hi and thanks,

But I think my own transcription and translation are closer to the original!  :P (I missed a capital "F" in "friends" though... :) )

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #106 on: August 04, 2014, 03:18:07 AM »
Rob,

Thanks for your input but this definition of floor() - and ffloor(), as a matter of fact - is not standard for C, C++, C#, SB, FBSL, etc. etc. etc. In these languages, floor() doesn't truncate towards negative infinity but rather towards zero. It is ceil() that would round 1.6 to 2, and -1.6, to -2.... :(

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #107 on: August 04, 2014, 03:18:28 AM »
Hi Mike :

I did write "selbs.... "     ;)  - an almost verical line ... but the font is not complete -- iir German had a "long" and a "round" s -- to avoid confusion in names as Riefenstahl  ...    is it composed from   riefen + stahl  or  riefens + tahl (?) , they are pronounced differently -- what many do not know is about the "ß"  -- this is a long "s" with a "z"    something as |3  - thus infact writing "groß" in capitals should be GROSZ   ...   like here :
http://www.gentblogt.be/wp-content/uploads/2006/08/20060802_dullegriet1.jpg

-------------------------------------------------------
Function FLOOR, FFLOOR, CEILING, FCEILING, TRUNCATE, FTRUNCATE, ROUND, FROUND

Syntax:


floor number &optional divisor => quotient, remainder

ffloor number &optional divisor => quotient, remainder

ceiling number &optional divisor => quotient, remainder

fceiling number &optional divisor => quotient, remainder

truncate number &optional divisor => quotient, remainder

ftruncate number &optional divisor => quotient, remainder

round number &optional divisor => quotient, remainder

fround number &optional divisor => quotient, remainder



Arguments and Values:


number---a real.

divisor---a non-zero real. The default is the integer 1.

quotient---for floor, ceiling, truncate, and round: an integer; for ffloor, fceiling, ftruncate, and fround: a float.

remainder---a real.


Description:


These functions divide number by divisor, returning a quotient and remainder, such that

quotient*divisor+remainder=number

The quotient always represents a mathematical integer. When more than one mathematical integer might be possible (i.e., when the remainder is not zero), the kind of rounding or truncation depends on the operator:




floor, ffloor

floor and ffloor produce a quotient that has been truncated toward negative infinity; that is, the quotient represents the largest mathematical integer that is not larger than the mathematical quotient.

ceiling, fceiling

ceiling and fceiling produce a quotient that has been truncated toward positive infinity; that is, the quotient represents the smallest mathematical integer that is not smaller than the mathematical result.

truncate, ftruncate

truncate and ftruncate produce a quotient that has been truncated towards zero; that is, the quotient represents the mathematical integer of the same sign as the mathematical quotient, and that has the greatest integral magnitude not greater than that of the mathematical quotient.

round, fround

round and fround produce a quotient that has been rounded to the nearest mathematical integer; if the mathematical quotient is exactly halfway between two integers, (that is, it has the form integer+1/2), then the quotient has been rounded to the even (divisible by two) integer.


All of these functions perform type conversion operations on numbers.

The remainder is an integer if both x and y are integers, is a rational if both x and y are rationals, and is a float if either x or y is a float.

ffloor, fceiling, ftruncate, and fround handle arguments of different types in the following way: If number is a float, and divisor is not a float of longer format, then the first result is a float of the same type as number. Otherwise, the first result is of the type determined by contagion rules; see Section 12.1.1.2 (Contagion in Numeric Operations).


Examples:



 (floor 3/2) =>  1, 1/2
 (ceiling 3 2) =>  2, -1
 (ffloor 3 2) =>  1.0, 1
 (ffloor -4.7) =>  -5.0, 0.3
 (ffloor 3.5d0) =>  3.0d0, 0.5d0
 (fceiling 3/2) =>  2.0, -1/2
 (truncate 1) =>  1, 0
 (truncate .5) =>  0, 0.5
 (round .5) =>  0, 0.5
 (ftruncate -7 2) =>  -3.0, -1
 (fround -7 2) =>  -4.0, 1
 (dolist (n '(2.6 2.5 2.4 0.7 0.3 -0.3 -0.7 -2.4 -2.5 -2.6))
   (format t "~&~4,1@F ~2,' D ~2,' D ~2,' D ~2,' D"
           n (floor n) (ceiling n) (truncate n) (round n)))
>>  +2.6  2  3  2  3
>>  +2.5  2  3  2  2
>>  +2.4  2  3  2  2
>>  +0.7  0  1  0  1
>>  +0.3  0  1  0  0
>>  -0.3 -1  0  0  0
>>  -0.7 -1  0  0 -1
>>  -2.4 -3 -2 -2 -2
>>  -2.5 -3 -2 -2 -2
>>  -2.6 -3 -2 -2 -3
=>  NIL


Side Effects: None.


Affected By: None.


Exceptional Situations: None.


See Also: None.


Notes:


When only number is given, the two results are exact; the mathematical sum of the two results is always equal to the mathematical value of number.

(function number divisor) and (function (/ number divisor)) (where function is any of one of floor, ceiling, ffloor, fceiling, truncate, round, ftruncate, and fround) return the same first value, but they return different remainders as the second value. For example:


 (floor 5 2) =>  2, 1
 (floor (/ 5 2)) =>  2, 1/2

If an effect is desired that is similar to round, but that always rounds up or down (rather than toward the nearest even integer) if the mathematical quotient is exactly halfway between two integers, the programmer should consider a construction such as (floor (+ x 1/2)) or (ceiling (- x 1/2)).

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

best , Rob

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #108 on: August 04, 2014, 03:28:52 AM »
Rob,

I'm aware of your "beta" ("ß") :D and I think this is exactly what I should type as "ss" if I don't have a German keyboard (is it an "azerty" keyboard similar to a French one by the way?)

Now can you please cook up some sort of a very simple loop for this Lisp usable for benchmarking, say, a factorial loop similar to Rosetta Code's

Code: [Select]
(defun fact (n)
  (if (< n 2)
      1
    (* n (fact(- n 1)))))

but using the vocabulary of this particular Lisp? You can find the description here.

The benchmark should provide for the user input of n if possible (if not then it can be hardcoded) and it should also give the printout of results using (print).

John and I would appreciate it if you could do it for us. :)

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #109 on: August 04, 2014, 03:53:56 AM »
Notice: "An meinen Freunden Aurel und Mike" is incorrect,  "An mein Freund Aurel und Mike"  is correct

Yes Peter,

I know it. You said I am not your friend any more and un-friended with me (in Facebook lingo). So from your perspective, it is only Aurel who is your friend. Am I correct in my deduction? :(

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #110 on: August 04, 2014, 04:11:23 AM »
Morning John,

Here comes your SB Lisp. Congrats! :)

(I've used your PVALUE<>NUMBER fixup - it seems reasonable, I've used <>undef following you recommendation, and I've also used INT() for lispish floor() based on Rob's input)

.

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #111 on: August 04, 2014, 05:21:46 AM »
IMHO ..   an meinem Freund then ,  it must be "Dativ" , not ??

Is there a list with functions and macro's of this Lisp -- the pdf gives some examples, but I'm not sure what's inside.
I tried to run the (what was it )   something with pc.exe - but it does not work with my keyboard .

So , answering the keyboard question :  it's Belgian   (in DOS   keyb be ), something rare which tries to mix a French AZERTY with a German (Dutch, French and German are the official languages here -- is the sequence of studying at school (except some Latin and old Greek is inserted before the German (for those who passed "the test" -- promoted and handled by the diosece -- especialy the "Societas Jesu" were interested in future intelligentsia under their flag  >:(   -- it's a looong time ago now !!

best Rob

gross (short o)  grosz (long o)  -- not sure Gross exists in German , normally it should mean a dozen of dozens (12x12)
the big gun attached (I had to post twice previously ..)

addendum :
---------------

if possible, I suggest next -- a lispish way to do the Fibonacci 

(define (fib x)
  (let ((nr '(0 1)))
   (dotimes (i x t)
     (setq nr (list (nth 1 nr) (+ (nth 0 nr) (nth 1 nr)))))
 (nth 1 nr)))

-- (fib 1000) in NewLisp is still below 0 mSec ..  question thus , do your Lisps have extended (big) integers like Common Lisp and NewLisp (and PicoLisp) ??

if this is ok, I'll give the Common Lisp version (Newlisp uses somewhat of Scheme like (define ( x y .... ) ... ) i.o. (defun x (y ... ) ...)



.
« Last Edit: August 04, 2014, 06:48:07 AM by RobbeK »

Charles Pegge

  • Guest
Re: Lisp in Basic
« Reply #112 on: August 04, 2014, 06:13:55 AM »
Quote
(defun fact (n)
  (if (< n 2)
      1
    (* n (fact(- n 1)))))

In Lispish, a simple looping operation can be done by using (iter n) instead of recursion.

Thus n factorial:
Code: [Select]
( let n 5 )
( * n ( iter n ) ) ; expands to ( * 5 4 3 2 1 )

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #113 on: August 04, 2014, 06:51:50 AM »
Rob,

IMHO ..   an meinem Freund then ,  it must be "Dativ" , not ??
I guess that's the question for Peter, not for me. ;)

Quote
Is there a list with functions and macro's of this Lisp -- the pdf gives some examples, but I'm not sure what's inside.
Unfortunately, the PDF is all we have. Its list of features is exhaustive for this implementation. Thanks for your code snippets anyway but they don't seem to go well with this implementation due to the lack of features.

Quote
I tried to run the (what was it )   something with pc.exe - but it does not work with my keyboard .
Not sure exactly what you mean but if you want to run this Lisp as an executable under Windows, you can use its FBSL adaptation. It wasn't optimized for speed and carried a lot of unnecessary rubbish like if asc("a") < asc("b") in place of if "a" < "b" just to be on the safe side while debugging, but it will work.

Quote
gross (short o)  grosz (long o)  -- not sure Gross exists in German , normally it should mean a dozen of dozens (12x12)
Yes, understood. I was just talking about the absence of a German keyboard layout (have a look at a QWERTY keyboard), in which case the typist is supposed to substitute a "beta" glyph with a double "s" -> "ss". At least this is what my wife's telling me. She's a Belarusian but she grew up in East Berlin and she also used to be a certified typist in her greener years.

Quote
the big gun attached (I had to post twice previously ..)
Yes, I got the SZ written there. BTW that one wasn't of the largest caliber actually. Царь-пушка (The Tzar Gun) in the Moscow Kremlin seems to be somewhat more impressive. :)




Hi Charles,

There's no (iter) in this Lisp but there's a (for-each) iterator in it. OK I'll try to make out what is what in it myself. Anyway it was me that succumbed to this venture... :)

P.S. This thing uses a Scheme, not Common Lisp, syntax...
« Last Edit: August 04, 2014, 08:13:14 AM by Mike Lobanovsky »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #114 on: August 04, 2014, 08:03:40 AM »
Hehehe,

Here's its syntax to calculate the factorial of 8 recursively. :D

Use (factorial X) in the function call to calc the factorial of any other X.


P.S. And I'll be d*mned, it does it instantly!



.

JRS

  • Guest
Re: Lisp in Basic
« Reply #115 on: August 04, 2014, 08:06:57 AM »
Quote from: Mike
John and I would appreciate it if you could do it for us.

It doesn't seem to work in SBLisp.

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
0](defun fact (n)
1]  (if (< n 2)
2]     1
2]    (* n (fact(- n 1)))))
ERROR: UNBOUND VARIABLE
0]

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #116 on: August 04, 2014, 08:17:25 AM »
Hi John,

Wrong syntax! Repeat 2: This thing uses Scheme, not Common Lisp, syntax : End Repeat

:D

JRS

  • Guest
Re: Lisp in Basic
« Reply #117 on: August 04, 2014, 08:31:09 AM »
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
0](define factorial (lambda (n)
2]  (if ((= n 0)
4]    1
4]    (* n (fractorial (- n 1)))))))
FACTORIAL
0](factorial 8)
ERROR: BAD TYPE IN CAR
0]

Not having much luck with SBLisp:-\

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #118 on: August 04, 2014, 08:36:21 AM »
There's a typo in your input, John. It should be (<= n 0) rather than ((= n 0). :)


AND IT SHOULD BE FACTORIAL, NOT FRACTORIAL!
« Last Edit: August 04, 2014, 08:43:23 AM by Mike Lobanovsky »

JRS

  • Guest
Re: Lisp in Basic
« Reply #119 on: August 04, 2014, 08:43:17 AM »
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
0](define factorial (lambda (n)
2](if (< n 0)
3]1
3](* n (fractorial (- n 1)))))))
FACTORIAL
0](factorial 8)
ERROR: IN <
0]

My first attempt was using your FBSL screen shot code which seems to work for you. The last correction didn't help.