Author Topic: TinyScheme  (Read 63617 times)

0 Members and 3 Guests are viewing this topic.

JRS

  • Guest
Re: TinyScheme
« Reply #30 on: August 25, 2014, 10:00:15 PM »
Quote
Regrets, oh.... excuse me... Regards,

Maybe Rob can create a macro or I can create a C foreign function for holes in TinyScheme? The TinyScheme API seems flexible and open.

Any chance we might see TinyScheme embedded in FBSL? (via libtinyscheme.dll)


Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #31 on: August 25, 2014, 10:10:56 PM »
Any chance we might see TinyScheme embedded in FBSL? (via libtinyscheme.dll)

Nope. FBSL will enjoy its own FBLisp -- with time. :)

Also, this init.scm looks very suspicious. Half the language is defined via its own macros. Unless it unrolls them to native code with its compiler, it will suffer from the same technical bottlenecks as Rob's ASCII Mandelbrot did in BL.

It would be more reasonable to move all this macro hell directly into the engine IMO.

JRS

  • Guest
Re: TinyScheme
« Reply #32 on: August 25, 2014, 10:19:11 PM »
Quote
It would be more reasonable to move all this macro hell directly into the engine IMO.

Once I successfully bind the TinyScheme API with SB then I will look at TinyScheme's misgivings. I'm waiting for a bitch list from Rob on what is missing but he isn't done yet discovering what is there and being happy about it. Let's not spoil the moment. (like Christmas morning for a Lisp programmer - who forgot the batteries? will come later)  :)

Don't forget the keyword here is scripting. I'm not trying to compete with MIT/GNU Scheme with this. All I'm after is a Lisp ext. module that works seamlessly with SB.
« Last Edit: August 25, 2014, 10:34:33 PM by John »

Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #33 on: August 26, 2014, 01:16:30 AM »
OK OK, let him fiddle with it for awhile.

In the meantime, this Wikipedia page contains, in its Review of standard forms and procedures section at the bottom of the page, complete tables of standard forms and procedures that represent Scheme's core language vocabulary in terms of r5rs and r6rs standards. All other language constructs were unofficial macro includes at the time of r5rs and became language extension libraries when r6rs came into force in 2012.

The both standards enumerate these core constructs in their respective specifications without reference to any extension library. They are thus forming up the language nucleus and they are the first thing that TS should be checked against. I found 3 missing standard numeric procedures concerning rational numbers out of 4. All four are already implemented in BL.  8)

JRS

  • Guest
Re: TinyScheme
« Reply #34 on: August 26, 2014, 01:22:26 AM »
You may want to look at s7 embeddable Lisp as it seems to be a contender to TinyScheme. It looks like Lisp & BASIC are in a variation war.  :o

Good Night.

.
« Last Edit: August 26, 2014, 01:39:47 AM by John »

RobbeK

  • Guest
Re: TinyScheme
« Reply #35 on: August 26, 2014, 01:52:18 AM »
...  all,

(numerator) etc.. are needed for systems having fractions.
The filosophy of Lisp is to work both with exact and inexact numbers 1/3 is an exact number 0.33333..  is not.

This means that in a Lisp with fractions (/ 1 3) -> 1/3 and (* 3 (/ 1 3)) -> 1 in tB p.e. and declaring the variable holding 1/3 being of the type single type this will deliver  .999998986.. 
This is one of the reasons that Common Lisp is used  in te Boyer-Moore family of provers to test the correctness of fpu's etc..
(after all even the  real numbers (floats) can be set up to do 1000s of digits & AI a solution may escape when not working with exact numbers.

However, both TinyScheme , Bigloo , & also NewLisp do not have fractions, nor complex numbers -- both or built-in in a way that directly work on the operators.  In CL   (+ 3 (sqrt -1)) , just works without the need of a special operator.
The FBMath lib from Mr Jean Debord does same for FB -- in FB it is possible to say   declare operator + .......

Bigloo does have (complex? ) , but only for the reason that every number is a complex number.

MITScheme / Scheme48 / DrRacket Scheme hold the standard , many others not in Scheme -- they are called practical then  ???

Every CL however, is very strict to the standard -- all programs without foreign functions or packages can be used on any CL system.

The fractions are easy to write , but I need to declare non-incorporated operators at first (like f+ , f- ...  fsqrt etc ...)  these however can be incorporated by macro's redefining the usual operators.  But we do have to think about their practical use first , as a prover it also should contain the bignummers etc...   and tiny will not be tiny anymore  8)

With the same ease, fractions can be set up for BL -- missing the tools the write syntax macro's they will keep carrying their specific operators. Something imho is not bad "an sich"  , because in CL (and the strict Schemes) it is sometimes difficult where to switch from exact to inexact numbers.

best, Rob

Some reading about the ACL2 prover can be read here : http://www.cs.utexas.edu/users/moore/publications/bkm96.pdf     

RobbeK

  • Guest
Re: TinyScheme
« Reply #36 on: August 26, 2014, 02:39:49 AM »
Addendum :

An exact number extention

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

(define (fr# a b) (list a b))

(define (simplef a)
      (let* ((p (car a)) (q (cadr a)) (s (gcd p q)))
         (list (/ p s) (/ q s))))

(define (fneg a)
   (list (* -1 (car a)) (cadr a)))

(define (finv a)
   (list (cadr a) (car a)))

(define (f+ a b)
    (let ((p (car a)) (q (cadr a)) (r (car b)) (s (cadr b)))
      (simplef (list (+ (* p s) (* r q)) (* q s)))))

(define (f- a b)
     (f+ a (fneg b)))

(define (f* a b)
     (let ((p (car a)) (q (cadr a)) (r (car b)) (s (cadr b)))
       (simplef (list (* p r) (* q s)))))

(define (f/ a b)
    (f* a (finv b)))

(define (fprint a)
   (display (car a)) (display "/") (display (cadr a)))

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

definitions in action :


TinyScheme 1.39
> (define a (fr# 1 3))
a
> (fprint (f+ a a))
2/3  #t
> (fprint (f- a a))
0/1  #t
> (fprint (f* a a))
1/9  #t
> (fprint (f/ a a))
1/1  #t
> (define b (fr# 3 4))
b
> (fprint (f* a b))
1/4  #t                               (remark  I coded it to simplify the fraction if possible )
> (fprint (f/ b a))
9/4  #t
> (fprint (f/ a b))
4/9  #t
>

------------------ to do :  the div zero exception (for conversion only , except for the simplifaction I avoided division and the gcd should never be 0 - but i have to test this ) ,  (fraction->inexact  )-------------   some cosmetics

such things are exactly the power of Lisp  --  Mike of course write it for BL too   (just need to define (gcd ) for you
(now denominator etc ... can be defined)
best Rob

extending further

(define (make-harmonic x)
  (let ((m '() ))
   (do ((i 1 (+ i 1)))
       ((= i x))
       (set! m (cons (fr# 1 i) m)))  (reverse m)))

(define (print-harmonic L)
   (map (lambda (x) (fprint x) (display " + ")) L)
   (display " ...."))

(define (calc-harmonic L fr )
   (if (null? L) fr
      (calc-harmonic (cdr L) (f+ fr (car L)))))
     
--------------in action -----------


> (define h (make-harmonic 20))
h
> (print-harmonic h)
1/1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7 + 1/8 + 1/9 + 1/10 + 1/11 + 1/12 + 1/13
+ 1/14 + 1/15 + 1/16 + 1/17 + 1/18 + 1/19 +  ....#t
> (calc-harmonic h (fr# 0 1))
(275295799 77597520)
 

> (fprint (calc-harmonic h (fr# 0 1) ))
275295799/77597520        #t
> 8)
Joh, ; there's also SLIB , but do not know any one connected it with TinyScheme (for Bigloo this extension can be linked)
« Last Edit: August 26, 2014, 04:51:41 AM by RobbeK »

Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #37 on: August 26, 2014, 04:40:56 AM »
Hi Rob,

Quote
(just need to define (gcd ) for you (now denominator etc ... can be defined)

GCD and SCM (a.k.a. LCM) are FBSL's intrinsic functions.

SBLisp will never have them unless rewritten in C and compiled with GCC.

(Sorry Rob, I'm very sleepy and can't comment on your info now without making a fool of myself... :) )

RobbeK

  • Guest
Re: TinyScheme
« Reply #38 on: August 26, 2014, 04:55:02 AM »
Hi Mike,

(define gcd
      (lambda (a b)
        (cond ((= a b) a)
              ((> a b) (gcd (- a b) b))
              (else    (gcd a (- b a))))))    ;)

best Rob

These are the Lisps with the "full numeric tower" :    Racket, Gauche, MIT, Gambit, Chicken with the numbers egg, Scheme48/scsh, Kawa, SISC, Chibi, Guile, Chez, Vicare, Larceny, Ypsilon, Mosh, IronScheme, STklos, KSi, UMB, Spark , R6RS, Common Lisp, Pure.
« Last Edit: August 26, 2014, 06:52:23 AM by RobbeK »

JRS

  • Guest
Re: TinyScheme
« Reply #39 on: August 26, 2014, 07:23:31 AM »
Code: [Select]
TinyScheme 1.39
> (define a (fr# 1 3))
a

Hi Rob,

Is the latest 1.41 version not working for you?


RobbeK

  • Guest
Re: TinyScheme
« Reply #40 on: August 26, 2014, 07:27:33 AM »
Hi John,

It works fine, no problems --  too lazy to rewrite the batch-file , it was still calling the 1.39 when the first 1.41 had no Math library activated .
BTW thanks for the dll / .a - will do some tests from within CL or NewLisp's ffi .

best Rob

JRS

  • Guest
Re: TinyScheme
« Reply #41 on: August 26, 2014, 07:29:41 AM »
Quote
there's also SLIB , but do not know any one connected it with TinyScheme (for Bigloo this extension can be linked)

I have read in the TinyScheme docs about SLIB or a sub-set of it being used. What dos SLIB bring to the table?

TS readme
Quote
    Things that keep missing, or that need fixing
     ---------------------------------------------

     There are no hygienic macros. No rational or
     complex numbers. No unwind-protect and call-with-values.

     Maybe (a subset of) SLIB will work with TinySCHEME...

Quote
Although it is a descendant of tinyScheme, s7 is closest as a Scheme dialect to Guile 1.8. I believe it is compatible with r5rs and r7rs: you can just ignore all the additions discussed in this file. It has continuations, ratios, complex numbers, macros, keywords, hash-tables, multiprecision arithmetic, generalized set!, unicode, and so on. It does not have syntax-rules or any of its friends, and it does not think there is any such thing as an inexact integer.

@Rob - Is there any benefit at the Lisp level for a TSION TinyScheme interface? My thoughts are that cURL would be used at the SB (BASIC) level rather than using some little known interface.

Quote
Quasiquoting

Scheme offers a very powerful facility called "quasiquoting" for creating lists that is especially useful for creating macros -- because the output of a macro body is expected to be a list. Quasiquoting is quite well-documented and so I won't go into too much detail about it, but the general premise is that code that has been quasiquoted will by default not be evaluated (just as with quoting), however, you can optionally 'unquote' parts of the expression.

This form of list generation generally results in macros that are much more recognizable with regard to the code being generated. For example, the body of the preceding 'when' macro would appear as follows in quasiquote notation:

  `(if ,(cadr form)
     (begin
       ,@(cddr form) ))

NOTE: this is precisely how the 'when' macro is defined in GIMP's "script-fu.init" file.
« Last Edit: August 26, 2014, 08:42:16 AM by John »

RobbeK

  • Guest
Re: TinyScheme
« Reply #42 on: August 26, 2014, 10:28:06 AM »
John,

With SLIB you would have some interesting extra packages ( see attached J 01)

TSION - don't know, very low expertise about such matters (?)  -- I'll read it, but not sure I can give a valuable answer.

Also attached, from RacketScheme , a full numeric tower Scheme -- fractions in action  (example of exact numbers)
(I have both the windows and linux version , all sources compile on both sides -- it compiles to bytcode source (it uses GNU Lightning JIT) - bundled exe - or installation packet )

best Rob



.

JRS

  • Guest
Re: TinyScheme
« Reply #43 on: August 26, 2014, 11:08:56 AM »
Personally, I'm not so keen about adding other than what is necessary to provide a standard Scheme in SB. I already have SDL GFX, cURL, MySQL, SQLite and other extension modules I can use with the results of my TinyScheme function calls.


Mike Lobanovsky

  • Guest
Re: TinyScheme
« Reply #44 on: August 26, 2014, 03:30:10 PM »
Hi Rob,

What determines the precision of LISP numerator and denominator in exact numbers? I'm seeing this:

(random 100/3)  => 170571694016427575/13510798882111488

however GCC's intrinsic 32-bit GCD and SCM cannot calc integers of such length. What we're seeing here are at least 64-bit long long ints.

So my question is: are exact numbers physically stored in LISP memory as actual numbers (one memory location for numerator, another one, for denominator) or are they simply generated once as two respective sequences of char strings and then re-read sequentially to perform some arith char by char?