Oxygen Basic

Information => Open Forum => Topic started by: JRS on August 23, 2014, 03:49:50 PM

Title: TinyScheme
Post by: JRS on August 23, 2014, 03:49:50 PM
(http://files.allbasic.info/TS/ts.png)


Quote
TinyScheme is a lightweight Scheme interpreter that implements as large a subset of R5RS as was possible without getting very large and complicated. It is meant to be used as an embedded scripting interpreter for other programs. As such, it does not offer IDEs or extensive toolkits although it does sport a small top-level loop, included conditionally. A lot of functionality in TinyScheme is included conditionally, to allow developers freedom in balancing features and footprint.

As an embedded interpreter, it allows multiple interpreter states to coexist in the same program, without any interference between them. Programmatically, foreign functions in C can be added and values can be defined in the Scheme environment. Being a quite small program, it is easy to comprehend, get to grips with, and use. TinyScheme was grown out of the MiniScheme distribution during the development of Ovrimos.

Author / project home page (http://tinyscheme.sourceforge.net/home.html)

Current TinyScheme source (http://sourceforge.net/projects/tinyscheme/files/) - SourceForge - 1.41

Github Repository (https://github.com/armornick/TinyScheme) - Windows makefile for MinGW - 1.40

TinyScheme Documentation (http://www.alphageeksinc.com/tinyscheme/doc-tinyscheme.html)

Scheme R5RS Spec. (http://www.schemers.org/Documents/Standards/R5RS/r5rs.pdf)

The Internet Scheme Repository (http://www.cs.indiana.edu/scheme-repository/)
Title: TinyScheme
Post by: JRS on August 23, 2014, 05:29:41 PM
While Mike is getting BASIC Lisp in shape and ready for testing, I thought I would experiment with TinyScheme (http://tinyscheme.sourceforge.net/) as it's embeddable and seems to have many of the syntax features Rob has been after. Here is my first test of Tiny Scheme embedding with C.

Helpful Scheme Tutorial (http://www.cs.hut.fi/Studies/T-93.210/schemetutorial/schemetutorial.html)

Code: [Select]
//
// Tiny example of embedding TinyScheme in your code
// by Dmitry Chestnykh <dmitry@codingrobots.com>
// Public domain
//
//
// Compile
// --------
// $ cc example.c -L./ -ltinyscheme -o example
//
// Note: if you want to statically, link, first compile tinyscheme as NOT standalone.
// To do this, change scheme.h: # define STANDALONE 0   (instead of 1)
// Then 'make'. Forget about errors. Remove libtinyscheme.so (leave only static library .a)
// And then compile this example as written above.
//
//
// Run
// ---
// $ ./example
//
// Output
// --------------
// Hello, world!
// Answer: 42

#include <stdio.h>

#define USE_INTERFACE 1

#include "scheme.h"
#include "scheme-private.h"

// display -- scheme function
// Example: (display "Hello")
// This version only displays strings
pointer display(scheme *sc, pointer args) {
  if (args!=sc->NIL) {
    if (sc->vptr->is_string(sc->vptr->pair_car(args)))  {
      char *str = sc->vptr->string_value(sc->vptr->pair_car(args));
      printf("%s", str);
    }
  }
  return sc->NIL;
}

// square -- scheme function
// Example: (square 3)
pointer square(scheme *sc, pointer args) {
  if (args!=sc->NIL) {
    if(sc->vptr->is_number(sc->vptr->pair_car(args))) {
      double v=sc->vptr->rvalue(sc->vptr->pair_car(args));
      return sc->vptr->mk_real(sc,v*v);
    }
  }
  return sc->NIL;
}


int main(void) {
  scheme *sc;
 
  // Init Scheme interpreter
  sc = scheme_init_new();
 
  // Load init.scm
  FILE *finit = fopen("init.scm", "r");
  scheme_load_file(sc, finit);
  fclose(finit);

  // Define square
  sc->vptr->scheme_define(
       sc,
       sc->global_env,
       sc->vptr->mk_symbol(sc, "square"),
       sc->vptr->mk_foreign_func(sc, square));

  // Define display
  sc->vptr->scheme_define(
       sc,
       sc->global_env,
       sc->vptr->mk_symbol(sc, "display"),
       sc->vptr->mk_foreign_func(sc, display));

  // Run first example
  char *hello_scm = "(display \"Hello, world!\\n\")";
  scheme_load_string(sc, hello_scm);

  // Run second example
  char *square_scm = "(display "
                     "  (string-append \"Answer: \" "
                     "    (number->string (square 6.480740698407859)) \"\\n\"))";
  scheme_load_string(sc, square_scm);
 
  // Bye!
  scheme_deinit(sc);
  return 0;
}

Output

jrs@laptop:~/tinyscheme/tinyscheme-1.41$ time ./tshello
Hello, world!
Answer: 42.0

real   0m0.017s
user   0m0.016s
sys   0m0.000s
jrs@laptop:~/tinyscheme/tinyscheme-1.41$

My interest in timing this wasn't to see how fast it could display Hello, world! or the square root of 6.480740698407859 but how long it took to load the init.scm support library which is a decent size file for a Scheme script.


.
Title: TinyScheme
Post by: JRS on August 23, 2014, 10:18:33 PM
Here is the beginning of the Script BASIC TinyScheme (TS) extension module. I think one of the coolest thing about TinyScheme is the mk_foreign_func that creates symbols on the fly in C. The init.scm also loads a set of default functions that smooths over many of the shortcomings of Scheme.

tshello.sb
Code: [Select]
' Tiny Scheme - extension module example

DECLARE SUB InitNew ALIAS "TS_init_new" LIB "ts"
DECLARE SUB Deinit ALIAS "TS_deinit" LIB "ts"
DECLARE SUB LoadStr ALIAS "TS_load_string" LIB "ts"

sc = InitNew()
LoadStr(sc, "(display \"Hello, world!\n\")")
Deinit(sc)

Output

jrs@laptop:~/sb/sb22/sblisp$ time scriba tshello.sb
Hello, world!

real   0m0.005s
user   0m0.008s
sys   0m0.000s
jrs@laptop:~/sb/sb22/sblisp$


TS ext. module interface file
Code: [Select]
// Tiny Scheme - Script BASIC extension module

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include "../../basext.h"
#include "cbasic.h"

#define USE_INTERFACE 1

#include "scheme.h"
#include "scheme-private.h"


pointer display(scheme *sc, pointer args) {
  if (args!=sc->NIL) {
    if (sc->vptr->is_string(sc->vptr->pair_car(args)))  {
      char *str = sc->vptr->string_value(sc->vptr->pair_car(args));
      printf("%s", str);
    }
  }
  return sc->NIL;
}


/****************************
 Extension Module Functions
****************************/

besVERSION_NEGOTIATE
  RETURN_FUNCTION((int)INTERFACE_VERSION);
besEND

besSUB_START
  DIM AS long *p;
  besMODULEPOINTER = besALLOC(sizeof(long));
  IF (besMODULEPOINTER EQ NULL) THEN_DO RETURN_FUNCTION(0);
  p = (long*)besMODULEPOINTER;
  RETURN_FUNCTION(0);
besEND

besSUB_FINISH
  DIM AS long *p;
  p = (long*)besMODULEPOINTER;
  IF (p EQ NULL) THEN_DO RETURN_FUNCTION(0);
  RETURN_FUNCTION(0);
besEND


/***********************
 Tiny Scheme Functions
***********************/

besFUNCTION(TS_init_new)
  DIM AS scheme PTR sc;
  sc = scheme_init_new();
  sc->vptr->scheme_define(
     sc,
     sc->global_env,
     sc->vptr->mk_symbol(sc, "display"),
     sc->vptr->mk_foreign_func(sc, display));
  besRETURN_LONG(sc);
besEND

besFUNCTION(TS_deinit)
  DIM AS scheme PTR sc;
  besARGUMENTS("i")
    AT sc
  besARGEND
  scheme_deinit(sc);
  besRETURNVALUE = NULL;
besEND
 
besFUNCTION(TS_load_string) 
  DIM AS scheme PTR sc;
  DIM AS char PTR cmdstr;
  besARGUMENTS("iz")
    AT sc, AT cmdstr
  besARGEND
  scheme_load_string(sc, cmdstr); 
  besRETURNVALUE = NULL;
besEND
Title: TinyScheme
Post by: JRS on August 24, 2014, 01:06:26 PM
Rob,

Would you mind giving TinyScheme a spin if you can find some time? I'm working on a Script BASIC extension module for it and a review by you before completion would be great. TS is used in GIMP as its scripting engine.

Title: TinyScheme
Post by: JRS on August 24, 2014, 03:31:17 PM
Rob,

I noticed that the version of TinyScheme (1.39) wasn't built with MinGW and was pretty old. I rebuilt the scheme.exe with current source. The SB TS ext. module for Windows will use the 1.41 code you will be testing. (see attached)

TinyScheme Windows 32 & Ubuntu 64 console interpreters attached.

.
Title: Re: TinyScheme
Post by: JRS on August 24, 2014, 07:30:39 PM
Rob,

I thought I would give your BL Mandelbrot script a try in TinyScheme. TS doesn't seem to like sequence.

Code: [Select]
jrs@laptop:~/tinyscheme/tinyscheme-1.41$ ./scheme
TinyScheme 1.41
ts> (define grid '())

(define mapped-grid '())



(define modulus

  (lambda (n d)

     (let (( r (floor (/ n d))))

      (- n (* r d)))))



(define cadr

    (lambda (L)

      (car (cdr L))))



(define sqrt

     (lambda (x)

       (exp (/ (log x) 2))))



(define sq (lambda(x) (* x x)))



(define 1- (lambda (x) (- x 1)))

(define 1+ (lambda (x) (+ x 1)))



(define level

 (lambda (i x y rc ic it orb)

  (if (or (= i it) (> orb 4)) i

    (level (1+ i) (+ rc (- (sq x) (sq y))) (+ ic (* 2 x y)) rc ic it (+ (sq x) (sq y))))))



(define mlevel

   (lambda (L)

     (level 0 (cadr L) (car L) (cadr L) (car L) 11 0)))



(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)))))



(define square-grid

   (lambda (nr x y dz)

     (fill-grid (1- nr) (+ x dz) dz nr y dz '() nr)))



(define map-grid

   (lambda (L)

     (map mlevel L)))



(define print*

  (lambda (x)

    (if (> x 9)

      (print x)

      (sequence (print x) (print '" ")) )))



(define print-grid

   (lambda (i it L)

     (if (null? L) T

       (if (= i it) (sequence (print* (car L)) (newline) (print-grid 0 it L))

         (sequence (print* (car L)) (print-grid (1+ i) it (cdr L)))))))



(define main

  (lambda ()

    (set! grid (square-grid 30 -1.7 -2.3 0.1))

    (set! mapped-grid (map-grid grid))

    (print-grid 0 30 mapped-grid)

))grid
ts> mapped-grid
ts> modulus
ts> cadr
ts> sqrt
ts> sq
ts> 1-
ts> 1+
ts> level
ts> mlevel
ts> fill-grid
ts> square-grid
ts> map-grid
ts> print*
ts> print-grid
ts> (main)
main
ts> Error: eval: unbound variable: sequence
Title: Re: TinyScheme
Post by: JRS on August 24, 2014, 09:26:28 PM
I found this TS embedding (in C) example that emulates a prompted lisp tutorial. I had to add the simulated (quit) logic.

Code: [Select]
/**
 *  hello-scheme for illustration how to embed
 *  the tiny scheme interpreter in a C program
 *
 *  2012, OL
 */

#include <stdio.h>
#include <string.h>
#include "scheme.h"
#include "dynload.h"


/* scheme_load_string does not like
   carriage returns so strip them out */
void strip_cr( char *p, int max_len )
{
  int i;

  for( i=0; i < max_len && p[i]!='\0'; ++i )
    ;

  if( i > 0 && p[i-1]=='\n' )
    p[i-1] = '\0';
}


/**
 * illustration of a C function binding
 */
pointer func1(scheme *sc, pointer args)
{
  pointer arg;
  pointer retval;
  char    *strarg;
  double  realnumber;
  int     intnumber;
  int     i = 1;

  while( args != sc->NIL )
  {
    if( is_string( arg = pair_car(args)) )
    {
      strarg = string_value( arg );
      printf( "argument %d is string %s\n", i++, strarg );
    }
    else if( is_real( arg = pair_car(args) ) )
    {
      realnumber = rvalue( arg );
      printf( "argument %d is real number %lf\n", i++, realnumber );
    }
    else if( is_integer( arg = pair_car(args) ) )
    {
      intnumber = ivalue( arg );
      printf( "argument %d is integer number %d\n", i++, intnumber );
    }

    args = pair_cdr( args );
  }

  if( i > 1 )
    retval = sc -> T;
  else
    retval = sc -> F;

  return(retval);
}


/*
 * Simple REPL
 */
int main( int argc, char* argv[] )
{
  scheme sc;

  char   cmd_str[80];


  /* intialize the scheme object */
  if( !scheme_init(&sc) ) {
    fprintf(stderr,"Could not initialize!\n");
    return 2;
  }

  /* set standard input and output ports */
  scheme_set_input_port_file(&sc, stdin);
  scheme_set_output_port_file(&sc, stdout);


  /* illustration how to define a "foreign" function
     implemented in C */
  scheme_define(&sc,sc.global_env,mk_symbol(&sc,"func1"),mk_foreign_func(&sc, func1));


  puts("Tiny Scheme REPL:");
  puts("try e.g. the following commands:");
  puts("   (write (+ 1 2))");
  puts("   (func1 \"hello\" 42 1.24)\n");

  do {
    printf("\n>");
    fgets( cmd_str, 80, stdin );
    strip_cr( cmd_str, 80 );
    if (strncmp(cmd_str,"(quit)",6)==0) break;
    scheme_load_string( &sc, cmd_str );
  } while(1);


  scheme_deinit(&sc);

  return 0;
}

Output

jrs@laptop:~/tinyscheme/tinyscheme-1.41$ ./testscm
Tiny Scheme REPL:
try e.g. the following commands:
   (write (+ 1 2))
   (func1 "hello" 42 1.24)


>(write (+ 1 2))
3
>(func1 "hello" 42 1.24)
argument 1 is string hello
argument 2 is integer number 42
argument 3 is real number 1.240000

>(quit)
jrs@laptop:~/tinyscheme/tinyscheme-1.41$
Title: Re: TinyScheme
Post by: JRS on August 24, 2014, 10:46:45 PM
I added the scheme_set_output_port_file(sc, stdout); TS function call to output more that just Display related responses. This TS extension module is basically functional with 3 calls to TinyScheme.  8)

Code: [Select]
' Tiny Scheme - extension module example

DECLARE SUB InitNew ALIAS "TS_init_new" LIB "ts"
DECLARE SUB Deinit ALIAS "TS_deinit" LIB "ts"
DECLARE SUB LoadStr ALIAS "TS_load_string" LIB "ts"

sc = InitNew()
LoadStr sc, "(write (+ 2 2)) (newline)"
Deinit sc

Output

jrs@laptop:~/sb/sb22/sblisp$ scriba tshello.sb
4
jrs@laptop:~/sb/sb22/sblisp$
Title: Re: TinyScheme
Post by: RobbeK on August 24, 2014, 11:46:26 PM
Hi John,

Downloaded, I'll convert the Mandelb for TinyScm --  (sequence ) is (begin ) in the R5RS standard. (and iirc (print ) should become (display ) )

best Rob
Title: Re: TinyScheme
Post by: JRS on August 24, 2014, 11:54:38 PM
Thanks Rob.

After the change, print is complaining.

Code: [Select]
jrs@laptop:~/tinyscheme/tinyscheme-1.41$ ./scheme
TinyScheme 1.41
ts> (load "mbrot.scm")
Loading mbrot.scm
Error: (mbrot.scm : 64) eval: unbound variable: print
jrs@laptop:~/tinyscheme/tinyscheme-1.41$
Title: Re: TinyScheme
Post by: JRS on August 25, 2014, 12:06:10 AM
I'll just wait until you post something. You may find a better way in TS.

Title: Re: TinyScheme
Post by: RobbeK on August 25, 2014, 12:13:29 AM
Change (print ) into (display ) -- I'll convert using iteration on some parts

best Rob
Title: Re: TinyScheme
Post by: JRS on August 25, 2014, 12:20:37 AM
Nope. Still doesn't work. The only print left is print-grid.

(write  worked for me in my ext. module test.
Title: Re: TinyScheme
Post by: RobbeK on August 25, 2014, 12:25:34 AM
John,

working on it --  the prints in definitions must remain (print-grid ) (print* ) etc...  (only the solitaire print must be replaced )

Rob
Title: Re: TinyScheme
Post by: JRS on August 25, 2014, 12:31:13 AM
Got it to work. (changed wrong program  >:( ) Still throws an error. Much faster than BL.

Code: [Select]
jrs@laptop:~/tinyscheme/tinyscheme-1.41$ time ./scheme mbrot.scm
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 1
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2 2 1
1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2 2 1
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3 2 1
1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3 3 1
1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3 3 1
1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3 3 1
1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3 3 1
1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4 3 1
1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4 3 1
1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4 3 1
1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4 3 1
1 1 1111111111111111111111111111111111111111111111117 5 4 3 1
1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4 3 1
1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4 3 1
1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4 3 1
1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4 3 1
1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3 3 1
1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3 3 1
1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3 3 1
1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3 3 1
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3 2 1
1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2 2 1
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2 2 1
1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 1
1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 Error: (mbrot.scm : 64) eval: unbound variable: t
Errors encountered reading mbrot.scm

real 0m2.293s
user 0m2.288s
sys 0m0.000s
jrs@laptop:~/tinyscheme/tinyscheme-1.41$
Title: Re: TinyScheme
Post by: RobbeK on August 25, 2014, 12:34:43 AM
John,

in the code change T  into #t and you're there -- I'll make an iterative version, so you can compare the speed


best Rob
Title: Re: TinyScheme
Post by: JRS on August 25, 2014, 12:37:48 AM
Sweet! Tried it from SB (ext. module) but it only shot blanks where the Mandelbrot should have displayed. Other than that, it worked.

Code: [Select]
(define grid '())
(define mapped-grid '())

(define modulus
  (lambda (n d)
     (let (( r (floor (/ n d))))
      (- n (* r d)))))

(define cadr
    (lambda (L)
      (car (cdr L))))

(define sqrt
     (lambda (x)
       (exp (/ (log x) 2))))

(define sq (lambda(x) (* x x)))

(define 1- (lambda (x) (- x 1)))
(define 1+ (lambda (x) (+ x 1)))

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

(define mlevel
   (lambda (L)
     (level 0 (cadr L) (car L) (cadr L) (car L) 11 0)))

(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)))))

(define square-grid
   (lambda (nr x y dz)
     (fill-grid (1- nr) (+ x dz) dz nr y dz '() nr)))

(define map-grid
   (lambda (L)
     (map mlevel L)))

(define display*
  (lambda (x)
    (if (> x 9)
      (display x)
      (begin (display x) (display '" ")) )))

(define print-grid
   (lambda (i it L)
     (if (null? L) #t
       (if (= i it) (begin (display* (car L)) (newline) (print-grid 0 it L))
         (begin (display* (car L)) (print-grid (1+ i) it (cdr L)))))))

(define main
  (lambda ()
    (set! grid (square-grid 30 -1.7 -2.3 0.1))
    (set! mapped-grid (map-grid grid))
    (print-grid 0 30 mapped-grid)
))
(main)
(quit)


Code: [Select]
jrs@laptop:~/tinyscheme/tinyscheme-1.41$ time ./scheme mbrot.scm
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 1
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2 2 1
1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2 2 1
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3 2 1
1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3 3 1
1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3 3 1
1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3 3 1
1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3 3 1
1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4 3 1
1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4 3 1
1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4 3 1
1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4 3 1
1 1 1111111111111111111111111111111111111111111111117 5 4 3 1
1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4 3 1
1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4 3 1
1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4 3 1
1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4 3 1
1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3 3 1
1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3 3 1
1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3 3 1
1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3 3 1
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3 2 1
1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2 2 1
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2 2 1
1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 1
1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2
real 0m2.377s
user 0m2.368s
sys 0m0.004s
jrs@laptop:~/tinyscheme/tinyscheme-1.41$
Title: Re: TinyScheme
Post by: RobbeK on August 25, 2014, 01:01:43 AM
Hi John,

Finished ...............

The source is at the bottom of the ini-file , this way it starts automatically when hitting the exec.
It's alot more compact with iteration ,   the Mandelbrot calc is recursive however ,   best of both worlds.

best Rob
TinyScheme, looks complete and powerfull

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

(newline)
(newline)
(display "Ascii Mandelbrot TinyScheme") (newline)
(display "---------------------------") (newline)

(define sq
   (lambda (x) (* x x)))

(define (1+ x) (+ x 1))
(define (1- x) (- x 1))

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

(define mlevel
   (lambda (L)
     (level 0 (cadr L) (car L) (cadr L) (car L) 11 0)))

(define (main)
   (let ((cnt 0) (lvl 0) (xo -1.7) (yo -2.3) (dz 0.1) )
     (do ((i 0 (1+ i)))
         ((= i 30))
        (do ((j 0 (1+ j)))
            ((= 30 j))
              (set! lvl (mlevel (list (+ xo (* i dz)) (+ yo (* j dz)) )))
              (if (< lvl 10)
                   (begin (display lvl) (display " "))
                   (display lvl))
              (set! cnt (1+ cnt))
              (when (= 30 cnt)
                 (set! cnt 0)
                 (newline))
))))
   
(main)

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



.
Title: Re: TinyScheme
Post by: JRS on August 25, 2014, 06:11:34 AM
Quote
TinyScheme, looks complete and powerful

Let's make that the quote of the day.  8)

mbrot2.scm
Code: [Select]
(newline)
(newline)
(display "Ascii Mandelbrot TinyScheme") (newline)
(display "---------------------------") (newline)

(define sq
   (lambda (x) (* x x)))

(define (1+ x) (+ x 1))
(define (1- x) (- x 1))

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

(define mlevel
   (lambda (L)
     (level 0 (cadr L) (car L) (cadr L) (car L) 11 0)))

(define (main)
   (let ((cnt 0) (lvl 0) (xo -1.7) (yo -2.3) (dz 0.1) )
     (do ((i 0 (1+ i)))
         ((= i 30))
        (do ((j 0 (1+ j)))
            ((= 30 j))
              (set! lvl (mlevel (list (+ xo (* i dz)) (+ yo (* j dz)) )))
              (if (< lvl 10)
                   (begin (display lvl) (display " "))
                   (display lvl))
              (set! cnt (1+ cnt))
              (when (= 30 cnt)
                 (set! cnt 0)
                 (newline))
))))

(main)
(quit)

Output

Code: [Select]
jrs@laptop:~/tinyscheme/tinyscheme-1.41$ time ./scheme mbrot2.scm


Ascii Mandelbrot TinyScheme
---------------------------
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2
1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2
1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3
1 1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3
1 1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3
1 1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3
1 1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4
1 1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4
1 1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4
1 1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4
1 1 1 1111111111111111111111111111111111111111111111117 5 4
1 1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4
1 1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4
1 1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4
1 1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4
1 1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3
1 1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3
1 1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3
1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2
1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2
1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2

real 0m0.660s
user 0m0.608s
sys 0m0.000s
jrs@laptop:~/tinyscheme/tinyscheme-1.41$

@Rob - How did you make the .exe version you sent in the zip?
Title: Re: TinyScheme
Post by: RobbeK on August 25, 2014, 10:19:08 AM
Hi John,

When something as GIMP uses it for its scripts , quatlity should be certified ...
The exe is a Lispish trick , it's the whole system renamed and the source of the program added in the init file  8)

However :  **********warning***************

The 1.41 is compiled with USE_MATH 0 ,  things like sin , cos , sqrt , floor ,ceiling etc etc will not work   - can you recompile with USE_MATH 1 ?  (i don't have a C compiler)

In the mean time switched  to 1.39  -- another benchmark test :  finding the primes below 5000  -- it's fast !!

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

(newline)
(display "start")
(newline)


(define (seq x)
   (let ((M '()))
     (do ((i 0 (+ i 1)))
         ((> i x))
         (set! M (cons i M))) M ))

(define numbers (reverse (seq 4999)))

 

(define (sieve L)
   (let ( ( len (- (length L) 2)) (vec (list->vector L)) )
     (do ((i 2 (+ i 1)))
         ((> i (floor (/ len 2))))
         
         (when (> (vector-ref vec i) 0)
            (do ((j 2 (+ j 1)))
                ((> (* i j) len))
               
                (vector-set! vec (* i j) 0)))) vec ))

(define (print-vec V)
   (let ((len (vector-length V)) (cnt 0) )
     (do (( i 2 (+ 1 i)))
         (( = i (- len 1)))
         (let (( item (vector-ref V i)))
           (when (not (= item 0))
              (set! cnt (+ 1 cnt))
              (display item)
              (display " ")))) cnt ))

(define (main)
  (let ((cnt 0))
   (newline)
   (display "calculating prime-numbers < 5000")  (newline)
   (display "--------------------------------")  (newline)
   (set! cnt (print-vec (sieve numbers)))
   (newline)
   (display "that's it")
   (newline)
   (display cnt) (display "  prime numbers found") ))


(main)   

---------------------------------------  attached in an exec.

It has vectors !!!  -- this is very ! important , vectors are "typed" and are indexed , lists not and have to be assigned in a recursive way -- this is much faster  ,  it's always possible to convert with (list->vector ) [if of a same type, of course , but calculations will speed up a lot ]  and (vector->list )   (unlike CL only one dimension is possible , but for 2D you can make a set of 2 vectors p.e.   for 3D - 3 etc...)

best Rob,  this looks very good
(oops yes for primes < 10000 , you will have to allocate more memory -- not sure it can be done without recompiling (but I do not know)





.
Title: Re: TinyScheme
Post by: JRS on August 25, 2014, 10:30:27 AM
Thanks for the feedback and positive news!

I will recompile the Windows 32 bit version enabling MATH and see if I can expand the memory limits. Is there anything else you want enabled?

Code: [Select]
#if USE_NO_FEATURES
define USE_MATH 1
# define USE_CHAR_CLASSIFIERS 0
# define USE_ASCII_NAMES 0
# define USE_STRING_PORTS 0
# define USE_ERROR_HOOK 0
# define USE_TRACING 0
# define USE_COLON_HOOK 0
# define USE_DL 0
# define USE_PLIST 0
#endif


Title: Re: TinyScheme
Post by: RobbeK on August 25, 2014, 11:42:48 AM
Hi John,

Maybe USE_TRACING 1 too ??     don't know it makes any sense in an embedded app.  , in the script (tracing) turns it on , and (tracing 0) off

From USE_DL, the documentation explains :
 USE_DL
     Enables dynamically loaded routines. If you define this symbol, you
     should also include dynload.c in your compile.

Once again - if embedded ??    -- but do the things following your needs , (only for playing with TinyScheme  the Math's are very welcome here , and certainly needed (for you) as an embedded app )

best Rob
Title: Re: TinyScheme
Post by: RobbeK on August 25, 2014, 12:05:58 PM
Perfect John  :)
addendum :
I think it's possible to allocate more memory-segments from within the script -- (without any need to recompile )
Title: Re: TinyScheme
Post by: JRS on August 25, 2014, 12:20:13 PM
Quote
I think it's possible to allocate more memory-segments from within the script -- (without any need to recompile )

That would be slick!  I didn't see anything obvious in the source to control memory use in the definition section.
Title: Re: TinyScheme
Post by: RobbeK on August 25, 2014, 12:34:32 PM
John,

 (new-segment <num>)
     Allocates more memory segments.

 :)

it has streams too , it seems (that little devil  8)     --  I'll study the documentation tomorrow , I had only a quick reading this morning from the init - file    --  I'm very surprised it's even capable to define your own syntax macro's just like its big brothers,

best Rob
Title: Re: TinyScheme
Post by: JRS on August 25, 2014, 01:52:12 PM
A lot of amazing in that little package and best of all faster than a speeding bullet. I'm happy!

jrs@laptop:~/tinyscheme/Rob$ time tinyscm primes.scm

start

calculating prime-numbers < 5000
--------------------------------
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973 4987 4993
that's it
668  prime numbers found
real   0m4.064s
user   0m4.052s
sys   0m0.004s
jrs@laptop:~/tinyscheme/Rob$

Here is a C primes example.

Code: [Select]
#include <stdio.h>

int main()
{
  int n1, n2=5000, i, j, flag;
  for(i=n1+1; i<n2; ++i)
  {
      flag=0;
      for(j=2; j<=i/2; ++j)
      {
        if(i%j==0)
        {
          flag=1;
          break;
        }
      }
      if(flag==0)
        printf("%d ",i);
  }
  return 0;

jrs@laptop:~/tinyscheme/Rob$ time ./primes
1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069 2081 2083 2087 2089 2099 2111 2113 2129 2131 2137 2141 2143 2153 2161 2179 2203 2207 2213 2221 2237 2239 2243 2251 2267 2269 2273 2281 2287 2293 2297 2309 2311 2333 2339 2341 2347 2351 2357 2371 2377 2381 2383 2389 2393 2399 2411 2417 2423 2437 2441 2447 2459 2467 2473 2477 2503 2521 2531 2539 2543 2549 2551 2557 2579 2591 2593 2609 2617 2621 2633 2647 2657 2659 2663 2671 2677 2683 2687 2689 2693 2699 2707 2711 2713 2719 2729 2731 2741 2749 2753 2767 2777 2789 2791 2797 2801 2803 2819 2833 2837 2843 2851 2857 2861 2879 2887 2897 2903 2909 2917 2927 2939 2953 2957 2963 2969 2971 2999 3001 3011 3019 3023 3037 3041 3049 3061 3067 3079 3083 3089 3109 3119 3121 3137 3163 3167 3169 3181 3187 3191 3203 3209 3217 3221 3229 3251 3253 3257 3259 3271 3299 3301 3307 3313 3319 3323 3329 3331 3343 3347 3359 3361 3371 3373 3389 3391 3407 3413 3433 3449 3457 3461 3463 3467 3469 3491 3499 3511 3517 3527 3529 3533 3539 3541 3547 3557 3559 3571 3581 3583 3593 3607 3613 3617 3623 3631 3637 3643 3659 3671 3673 3677 3691 3697 3701 3709 3719 3727 3733 3739 3761 3767 3769 3779 3793 3797 3803 3821 3823 3833 3847 3851 3853 3863 3877 3881 3889 3907 3911 3917 3919 3923 3929 3931 3943 3947 3967 3989 4001 4003 4007 4013 4019 4021 4027 4049 4051 4057 4073 4079 4091 4093 4099 4111 4127 4129 4133 4139 4153 4157 4159 4177 4201 4211 4217 4219 4229 4231 4241 4243 4253 4259 4261 4271 4273 4283 4289 4297 4327 4337 4339 4349 4357 4363 4373 4391 4397 4409 4421 4423 4441 4447 4451 4457 4463 4481 4483 4493 4507 4513 4517 4519 4523 4547 4549 4561 4567 4583 4591 4597 4603 4621 4637 4639 4643 4649 4651 4657 4663 4673 4679 4691 4703 4721 4723 4729 4733 4751 4759 4783 4787 4789 4793 4799 4801 4813 4817 4831 4861 4871 4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973 4987 4993 4999
real   0m0.011s
user   0m0.004s
sys   0m0.004s
jrs@laptop:~/tinyscheme/Rob$
Title: TinyScheme - 1.41 Download
Post by: JRS on August 25, 2014, 06:34:31 PM
Rob,

I have correctly built the TinyScheme 1.41 release on Windows XP using the latest MinGW-TDM GCC. The attached zip also includes the libtinyscheme.dll, libtinyscheme.a and the makefile I changed for MinGW use. I also included the Ubuntu 64 bit version. (console mode TinySchmene executable, init.scm and Manual.txt only - get the distribution from SourceForge (http://sourceforge.net/projects/tinyscheme/files/) to rebuild)

Please Test!




.
Title: Re: TinyScheme
Post by: JRS on August 25, 2014, 08:31:28 PM
Rob,

I download the RE (regular expression) extension for TinyScheme. I'm going to try and compile the re.so under Linux and if it seems to work then I'll create a re.dll for you to test. Until then here is re.scm option. The code is over 12 years old. If you think it would be worth building a C RE extension module then I will have to dig up current source. The readme said it was experimental (at the time) so I have no idea of its current state. Nice to have the .scm version of it though.


Quote from: README.1st
             TinyScheme RE (Regular Expressions) extension
             ---------------------------------------------
Version 1.2, August 2002

The bulk of this directory is the regular expression library written
by Henry Spencer (see file README and COPYRIGHT).

Two files were added to produce the TinyScheme regular expression
library, re.so: re.c and re.makefile. The included re.makefile was contributed
initially by Stephen Gildea and should be adaptable to all Unix systems.

The makefile produces a DLL named re.so. For now, it contains just
a single foreign function (re-match <pattern> <string>). It returns
true (string matches pattern) or false. If it is called with an
extra parameter, which should be a vector, overwrites as many elements
of the vector as needed with the strings that matched the corresponding
parenthesized subexpressions inside <pattern>.

It is not fully tested, so use with caution.

Load the extension from inside TinyScheme using
(load-extension "re/re")
assuming that re.so is in the directory "re".

Load "re.scm" if you wish to use v.1.1 behavior.


Code: [Select]
;; return the substring of STRING matched in MATCH-VECTOR,
;; the Nth subexpression match (default 0).
(define (re-match-nth string match-vector . n)
  (let ((n (if (pair? n) (car n) 0)))
    (substring string (car (vector-ref match-vector n))
                    (cdr (vector-ref match-vector n)))))

(define (re-before-nth string match-vector . n)
  (let ((n (if (pair? n) (car n) 0)))
    (substring string 0 (car (vector-ref match-vector n)))))

(define (re-after-nth string match-vector . n)
  (let ((n (if (pair? n) (car n) 0)))
    (substring string (cdr (vector-ref match-vector n))
             (string-length string))))

Title: TinyScheme - DLLC
Post by: JRS on August 25, 2014, 09:15:58 PM
Charles,

I would like to try TinyScheme with SB and DLLC. Based on the TS docs, I can run multiple TS objects in a single process without issue. This looks like a perfect (non-IUP) multi-threaded use of DLLC. Can you generate a DLLC definition for TinyScheme? The API is reasonably small.

The libtinyscheme.dll was included in the previous TinyScheme 1.41 Windows 32 attachment.



Title: Re: TinyScheme - 1.41 Download
Post by: Mike Lobanovsky on August 25, 2014, 09:48:19 PM
Please Test!

Misses (numerator), (denominator), and (rationalize) that must be part of core language as per the r5rs and r6rs standards of the Scheme language.


Regrets, oh.... excuse me... Regards,
Title: Re: TinyScheme
Post by: JRS 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)

Title: Re: TinyScheme
Post by: Mike Lobanovsky 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.
Title: Re: TinyScheme
Post by: JRS 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.
Title: Re: TinyScheme
Post by: Mike Lobanovsky on August 26, 2014, 01:16:30 AM
OK OK, let him fiddle with it for awhile.

In the meantime, this Wikipedia page (http://en.wikipedia.org/wiki/Scheme_%28programming_language%29) 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)
Title: Re: TinyScheme
Post by: JRS on August 26, 2014, 01:22:26 AM
You may want to look at s7 (https://ccrma.stanford.edu/software/snd/snd/s7.html) embeddable Lisp as it seems to be a contender to TinyScheme. It looks like Lisp & BASIC are in a variation war.  :o

Good Night.

.
Title: Re: TinyScheme
Post by: RobbeK 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     
Title: Re: TinyScheme
Post by: RobbeK 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)
Title: Re: TinyScheme
Post by: Mike Lobanovsky 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... :) )
Title: Re: TinyScheme
Post by: RobbeK 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.
Title: Re: TinyScheme
Post by: JRS 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?

Title: Re: TinyScheme
Post by: RobbeK 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
Title: Re: TinyScheme
Post by: JRS 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 (http://www.geonius.com/software/tsion/#software) 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.
Title: Re: TinyScheme
Post by: RobbeK 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



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

Title: Re: TinyScheme
Post by: Mike Lobanovsky 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?
Title: Re: TinyScheme
Post by: RobbeK on August 27, 2014, 01:52:36 AM
Hi Mike,

It are arrays (or vectors talking Scheme) of the digit type

http://www.clisp.org/impnotes/num-concepts.html

oops , page seems down :  from my documentation

------------------------------------------
12.2.2.2. Bignum Limits

BIGNUMs are limited in size. Their maximum size is 32*(216-2)=2097088 bits. The largest representable BIGNUM is therefore 2^2097088-1.
12.2.2.3. Float Limits

Together with PI, the other LONG-FLOAT constants
LEAST-NEGATIVE-LONG-FLOAT   LONG-FLOAT-EPSILON
LEAST-NEGATIVE-NORMALIZED-LONG-FLOAT   LONG-FLOAT-NEGATIVE-EPSILON
LEAST-POSITIVE-LONG-FLOAT   MOST-NEGATIVE-LONG-FLOAT
LEAST-POSITIVE-NORMALIZED-LONG-FLOAT   MOST-POSITIVE-LONG-FLOAT

are recomputed whenever (EXT:LONG-FLOAT-DIGITS) is SETFed. They are not constant variables.
Warning

Since the exponent of a LONG-FLOAT is a signed 32-bits integer, MOST-POSITIVE-LONG-FLOAT is about 2231, which is much larger that the largest representable BIGNUM, which is less than 2221. This, obviously, means that ROUND, TRUNCATE, FLOOR and CEILING SIGNALs an ERROR on large LONG-FLOATs. Less obviously, this means that (FORMAT NIL "~E" MOST-POSITIVE-LONG-FLOAT) also fails.

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

NewLisp uses the GMP  library which is only limitid by the available memory :
https://gmplib.org/pi-with-gmp.html

Speaking about big-numbers and Lisp macro's , I wrote something to memoize Fibonacci numbers //  I'll work out something more clever, memoizing all fibonacci numbers lower than an entry  -- here, try 30000 and 30000 again (the second time is should take no time)

(showing how Lisp becomes a programmable programming language )

best Rob    (btw : this is Lisp running in interpreted mode)
---  also found a pdf describing the first LISP written by McCarthy (MIT) from the end 1950s  -- could be perfectly rewritten/ simulated  by a modern CL/Scheme/NewLisp app.

--  addendum , (after some thinking) a more clever memoizing needs the definition to be resursive in the way the "index" is counted down , this way it can stop calculation the moment a (lower) value matches.
NewLisp has very limited recursive capabilities and CLisp doesn't do tail call optimizations -- GCL does and also (most?) Schemes , but the question is , when the compiler converts into iteration is the function than still recongnizable for memoizing ??  (is there a difference between lexical and dynamical scoping then ????)

-- addendum 2 :   8)  it works !!!  functions need to be declared in a recursive way so that the memoized can be recongized during execution.
Due to the very limited stack in example 2 start with 100 (higher numbers will crash the system) , now you can build up higher p.e. (fib 120 will take no time , because (fib 100) is already known -- hmm , one can build in steps of 100 upwards  now, every multiple of 100 will be memoized then , and every calculation < the highest memoized will take no time ... 
yes, final result added in memofinal.exe -- calculations below 100000 should take no time now


.
Title: Re: TinyScheme
Post by: JRS on August 27, 2014, 07:42:46 AM
Here is a nm dump of the libtinyscheme.so shared object. What has me confused if the following call.

void scheme_set_output_port_string(scheme *sc, char *start, char *past_the_end);

Do I pass a SB buffer string for start and  CHR$(0) for past_the_end?

It looks to me that this function is asking for a character in some string buffer to start with and a character beyond the end the string you want. Like a MID$() I guess. I'm open to all thoughts on how this is suppose to work.


Code: [Select]
jrs@laptop:~/tinyscheme/tinyscheme-1.41$ nm libtinyscheme.so
0000000000007c22 t Eval_Cycle
0000000000211db0 a _DYNAMIC
00000000000079f2 t _Error_1
0000000000211fe8 a _GLOBAL_OFFSET_TABLE_
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
                 w _Jv_RegisterClasses
0000000000011608 r __FRAME_END__
0000000000211ca0 d __JCR_END__
0000000000211ca0 d __JCR_LIST__
0000000000213bc0 d __TMC_END__
0000000000213bc0 A __bss_start
                 U __ctype_b_loc@@GLIBC_2.3
                 U __ctype_tolower_loc@@GLIBC_2.3
                 U __ctype_toupper_loc@@GLIBC_2.3
                 w __cxa_finalize@@GLIBC_2.2.5
00000000000056b0 t __do_global_dtors_aux
0000000000211c98 t __do_global_dtors_aux_fini_array_entry
0000000000212340 d __dso_handle
                 U __fprintf_chk@@GLIBC_2.3.4
0000000000211c90 t __frame_dummy_init_array_entry
                 w __gmon_start__
                 U __isoc99_sscanf@@GLIBC_2.7
                 U __printf_chk@@GLIBC_2.3.4
                 U __snprintf_chk@@GLIBC_2.3.4
                 U __stack_chk_fail@@GLIBC_2.4
                 U __strcat_chk@@GLIBC_2.3.4
                 U __strcpy_chk@@GLIBC_2.3.4
0000000000007817 T _cons
0000000000213bc0 A _edata
0000000000213bf0 A _end
000000000000eb14 T _fini
0000000000004fb0 T _init
0000000000005f15 t _s_return
                 U access@@GLIBC_2.2.5
                 U acos@@GLIBC_2.2.5
00000000000059d6 t alloc_cellseg
                 U asin@@GLIBC_2.2.5
00000000000079de t assign_syntax
                 U atan2@@GLIBC_2.2.5
                 U atan@@GLIBC_2.2.5
0000000000007026 t atom2str
0000000000006d3e t backchar
0000000000005620 t call_gmon_start
                 U ceil@@GLIBC_2.2.5
00000000000057ac T charvalue
0000000000005894 T closure_code
0000000000005899 T closure_env
0000000000213bc0 b completed.6976
                 U cos@@GLIBC_2.2.5
0000000000005640 t deregister_tm_clones
0000000000212520 d dispatch_table
                 U dlerror@@GLIBC_2.2.5
                 U dlopen@@GLIBC_2.2.5
                 U dlsym@@GLIBC_2.2.5
000000000000cad4 T eqv
                 U exp@@GLIBC_2.2.5
                 U fclose@@GLIBC_2.2.5
                 U fgetc@@GLIBC_2.2.5
0000000000005d9b t file_interactive
0000000000005ba8 t fill_vector
0000000000005b29 t find_consecutive_cells
0000000000005e5c t find_slot_in_env
                 U floor@@GLIBC_2.2.5
                 U fmod@@GLIBC_2.2.5
                 U fopen@@GLIBC_2.2.5
                 U fputc@@GLIBC_2.2.5
                 U fputs@@GLIBC_2.2.5
00000000000056f0 t frame_dummy
                 U free@@GLIBC_2.2.5
                 U fwrite@@GLIBC_2.2.5
0000000000006276 t gc
000000000000791e T gensym
00000000000065e2 t get_cell
00000000000064e3 t get_cell_x
                 U getenv@@GLIBC_2.2.5
0000000000005e2c t hash_fn
0000000000006cc8 t inchar
0000000000006043 t is_any
000000000000577d T is_character
0000000000005876 T is_closure
000000000000589e T is_continuation
00000000000058bc T is_environment
000000000000585e T is_foreign
00000000000058cb T is_immutable
00000000000057c0 T is_inport
00000000000077a2 T is_integer
0000000000006030 t is_list
0000000000005885 T is_macro
00000000000077f0 t is_nonneg
000000000000574e T is_number
0000000000005e01 t is_one_of
00000000000057e3 T is_outport
0000000000005806 T is_pair
00000000000057b1 T is_port
000000000000584f T is_proc
00000000000058ad T is_promise
000000000000575d T is_real
0000000000005730 T is_string
000000000000582f T is_symbol
0000000000005847 T is_syntax
000000000000573f T is_vector
000000000000579a T ivalue
0000000000005fa5 T list_length
0000000000009540 t list_star
                 U log@@GLIBC_2.2.5
000000000000e591 T main
                 U malloc@@GLIBC_2.2.5
0000000000005c7b t mark
                 U memcpy@@GLIBC_2.14
                 U memset@@GLIBC_2.2.5
000000000000820e t mk_atom
000000000000664a T mk_character
00000000000067e0 t mk_closure
00000000000066ed T mk_counted_string
000000000000b532 T mk_empty_string
000000000000662b T mk_foreign_func
000000000000666f T mk_integer
00000000000066c5 t mk_number
000000000000676d t mk_port
0000000000006692 T mk_real
0000000000006a29 t mk_sharp_const
0000000000006741 T mk_string
00000000000078ef T mk_symbol
0000000000006806 t mk_vector
                 U modf@@GLIBC_2.2.5
0000000000009f9b t new_frame_in_env
000000000000a083 t new_slot_in_env
0000000000009fe4 t new_slot_spec_in_env
00000000000058da t num_eq
00000000000059ba t num_ge
000000000000592a t num_gt
00000000000059c8 t num_le
0000000000005972 t num_lt
0000000000213bd0 b num_one
0000000000213be0 b num_zero
0000000000005791 T nvalue
000000000000785b t oblist_add_by_name
000000000000610e t oblist_find_by_name
000000000000a0e9 t opexe_0
000000000000d348 t opexe_1
000000000000b587 t opexe_2
000000000000cc12 t opexe_3
00000000000095b7 t opexe_4
0000000000008509 t opexe_5
0000000000007fa8 t opexe_6
0000000000005815 T pair_car
000000000000581a T pair_cdr
0000000000006049 t port_close
000000000000678c t port_from_string
0000000000005dcf t port_rep_from_file
                 U pow@@GLIBC_2.2.5
00000000000076e2 t printatom
00000000000065a6 t push_recent_alloc
000000000000698a T putcharacter
                 U puts@@GLIBC_2.2.5
00000000000061f9 T putstr
0000000000006d7f t readstr_upto
0000000000006176 t realloc_port_string
0000000000005670 t register_tm_clones
0000000000006903 t reserve_cells
000000000000778f T rvalue
0000000000009f88 t s_cons
0000000000009f75 t s_immutable_cons
0000000000008483 t s_save
000000000000a09e T scheme_define
000000000000e309 T scheme_deinit
000000000000e228 T scheme_init
000000000000ddb0 T scheme_init_custom_alloc
000000000000e244 T scheme_init_new
000000000000e1ec T scheme_init_new_custom_alloc
000000000000e57e T scheme_load_file
000000000000e45e T scheme_load_named_file
0000000000007ed3 T scheme_load_string
000000000000e301 T scheme_set_external_data
000000000000e273 T scheme_set_input_port_file
000000000000e2a3 T scheme_set_input_port_string
000000000000e2ba T scheme_set_output_port_file
000000000000e2ea T scheme_set_output_port_string
000000000000e970 T scm_load_ext
000000000000581f T set_car
0000000000005827 T set_cdr
0000000000005c4d t set_vector_elem
00000000000058d3 T setimmutable
                 U sin@@GLIBC_2.2.5
                 U snprintf@@GLIBC_2.2.5
                 U sqrt@@GLIBC_2.2.5
                 U stderr@@GLIBC_2.2.5
                 U stdin@@GLIBC_2.2.5
                 U stdout@@GLIBC_2.2.5
0000000000006082 t store_string
                 U strcasecmp@@GLIBC_2.2.5
                 U strcpy@@GLIBC_2.2.5
000000000000578c T string_value
00000000000069f0 t strlwr
                 U strrchr@@GLIBC_2.2.5
                 U strstr@@GLIBC_2.2.5
                 U strtod@@GLIBC_2.2.5
                 U strtol@@GLIBC_2.2.5
000000000000583e T symname
000000000000586d T syntaxname
                 U tan@@GLIBC_2.2.5
0000000000211cc0 d tests
0000000000006dfb t token
                 U ungetc@@GLIBC_2.2.5
0000000000005c24 t vector_elem
0000000000212360 d vtbl
jrs@laptop:~/tinyscheme/tinyscheme-1.41$
Title: Re: TinyScheme
Post by: JRS on August 27, 2014, 08:17:25 AM
I found a great resource for TinyScheme docs. The EDE Library API reference (http://equinox-project.org/api/edelib/index.html). The project uses TinyScheme and has provided some documentation for the TS function calls.

Quote
#define edelib_scheme_set_output_port_string   scheme_set_output_port_string

Set character array as output port. You should give pointer to the first element and pointer to the last.

@Charles - Didn't you add C array / type structure creation and access functions in DLLC?
Title: Re: TinyScheme
Post by: Charles Pegge on August 27, 2014, 09:48:57 AM
Hi John,

I hope this helps:

1 for your buffer, make a string of nuls (64kbytes for example)
2 get the real pointer to this string
3 calculate the end pointer
4 declare the lisp output port function to accept integers (instead of char*)
5 pass these values to the lisp output port function

creating the buffer and its string pointers:
Code: [Select]
  include "dllcinc.sb"
  lispbuf=string(0x10000,chr(0))
  lispstrptr=dllsptr(lispbuf)
  lispstrend=lispstrptr+0x10000 - 1
  dllprnt hex(lispstrptr) & "\n" & hex(lispstrend) & "\n"
  dlllnpt "Press Enter"
' ...

Title: Re: TinyScheme
Post by: JRS on August 27, 2014, 09:50:33 AM
Slick trick!

I'll give it a try.

Thanks Charles!

Title: Re: TinyScheme
Post by: JRS on August 27, 2014, 08:46:42 PM
Code: [Select]
' TinyScheme Script BASIC DLLC Example

DECLARE SUB dllfile ALIAS "dllfile" LIB "dllc"
DECLARE SUB dllproc ALIAS "dllproc" LIB "dllc"
DECLARE SUB dllcall ALIAS "dllcall" LIB "dllc"
DECLARE SUB dllsptr ALIAS "dllsptr" LIB "dllc"

ts = dllfile("libtinyscheme.dll")
InitNew = dllproc(ts, "scheme_init_new i = ()")
RtnStr = dllproc(ts, "scheme_set_output_port_string (i sc, i startptr, i endptr)")
Deinit = dllproc(ts, "scheme_deinit (i sc)")
LoadStr = dllproc(ts, "scheme_load_string (i sc, c *cmd)")

sc = dllcall(InitNew)
lispbuf = string(1024,CHR(0))
lispstrptr = dllsptr(lispbuf)
lispstrend = lispstrptr + 1024 - 1
dllcall(RtnStr, sc, lispstrptr, lispstrend)
dllcall(LoadStr, sc, "(display \"Thank You Charles!\")")
strlen = INSTR(lispbuf, CHR(0))
PRINT LEFT(lispbuf, strlen - 1),"\n"
dllcall(Deinit, sc)

dllfile()

C:\SB22\TS>scriba dllchellots.sb
Thank You Charles!

C:\SB22\TS>
Title: Re: TinyScheme
Post by: JRS on August 27, 2014, 09:47:14 PM
Code: [Select]
' TinyScheme Script BASIC DLLC Example

DECLARE SUB dllfile ALIAS "dllfile" LIB "dllc"
DECLARE SUB dllproc ALIAS "dllproc" LIB "dllc"
DECLARE SUB dllcall ALIAS "dllcall" LIB "dllc"
DECLARE SUB dllsptr ALIAS "dllsptr" LIB "dllc"

ts = dllfile("libtinyscheme.dll")
InitNew = dllproc(ts, "scheme_init_new i = ()")
RtnStr = dllproc(ts, "scheme_set_output_port_string (i sc, i startptr, i endptr)")
Deinit = dllproc(ts, "scheme_deinit (i sc)")
LoadStr = dllproc(ts, "scheme_load_string (i sc, c *cmd)")

sc = dllcall(InitNew)
lispbuf = string(4096,CHR(0))
lispstrptr = dllsptr(lispbuf)
lispstrend = lispstrptr + 4096 - 1
dllcall(RtnStr,sc, lispstrptr, lispstrend)
dllcall(LoadStr, sc, "(load \"init.scm\")")
dllcall(LoadStr, sc, "(load \"mbrot2.scm\")")
strlen = INSTR(lispbuf, CHR(0))
PRINT LEFT(lispbuf, strlen - 1),"\n"
dllcall(Deinit, sc)

dllfile()

Output

Code: [Select]
C:\SB22\TS>ptime scriba dllchellots.sb

ptime 1.0 for Win32, Freeware - http://www.pc-tools.net/
Copyright(C) 2002, Jem Berkes <jberkes@pc-tools.net>

=== scriba dllchellots.sb ===


Ascii Mandelbrot TinyScheme
---------------------------
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2
1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2
1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3
1 1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3
1 1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3
1 1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3
1 1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4
1 1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4
1 1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4
1 1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4
1 1 1 1111111111111111111111111111111111111111111111117 5 4
1 1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4
1 1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4
1 1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4
1 1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4
1 1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3
1 1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3
1 1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3
1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2
1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2
1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2


Execution time: 1.086 s

C:\SB22\TS>
Title: Re: TinyScheme
Post by: JRS on August 27, 2014, 10:50:22 PM
Rob, Mike and Charles,

I want to thank you guys for all the effort that was put into adding Lisp to BASIC. I'm at a point where I'm ready to move the TinyScheme extension module over to the Script BASIC forum where a thread already exists. The only non-member of the group is Mike. I offered to register Mike on the SB forum but he declined.  :-\  I hope to see Rob and Charles (if he has time) giving their input and direction on the SB forum as this interface matures.

FYI - The SB forum has color syntax highlighting for SB, Scheme and C. (among others)

FWIW - No Aurel on the SB forum.
Title: Re: TinyScheme
Post by: RobbeK on August 28, 2014, 10:35:44 AM
Hi John,

I'll try to make some time for it ... if you need more demo's etc...  just ask.

Tested the TinyScheme for numeric values , it's more than OK (series of 10000 sums , most of them inexact numbers -- put it against the Austin Kyoto CL compiler -- and once again, the speed is very good being interpretive ...

best Rob
(it *is* important this Scheme is capable of syntax macro's -- see my example under Lisp in Basic -- it's NewLisp, but in principle the same works in TinyScheme)

.
Title: Re: TinyScheme
Post by: JRS on August 28, 2014, 12:04:40 PM
Did you time these variations?  It would be nice to see how they compare.

Can you post a Mandelbrot iterator for TinyScheme like the one your did for BL?

It would be great if you can participate on both O2 & SB forums. (our Lisp hero)
Title: Re: TinyScheme
Post by: JRS on August 28, 2014, 06:29:12 PM
Here is a multi-threaded TinyScheme example using the DLLC Script BASIC extension module.

Start Script
Code: [Select]
' Boot (Main / Launcher)

DECLARE SUB dlltran ALIAS "dlltran" LIB "dllc"
DECLARE SUB dllclos ALIAS "dllclos" LIB "dllc"
DECLARE SUB dllfile ALIAS "dllfile" LIB "dllc"

t1 = dlltran("T1.sb","main::main",1)
t2 = dlltran("T2.sb","main::main",2)

LINE INPUT wait

dllclos t1, t2
dllfile

Thread Scripts - T1.sb & T2.sb are identical except for the (display ...) statement.
Code: [Select]
' Thread #1 Script

DECLARE SUB dllfile ALIAS "dllfile" LIB "dllc"
DECLARE SUB dllproc ALIAS "dllproc" LIB "dllc"
DECLARE SUB dllcall ALIAS "dllcall" LIB "dllc"
DECLARE SUB dllsptr ALIAS "dllsptr" LIB "dllc"

ts = dllfile("libtinyscheme.dll")
InitNew = dllproc(ts, "scheme_init_new i = ()")
RtnStr = dllproc(ts, "scheme_set_output_port_string (i sc, i startptr, i endptr)")
Deinit = dllproc(ts, "scheme_deinit (i sc)")
LoadStr = dllproc(ts, "scheme_load_string (i sc, c *cmd)")

FUNCTION main(pProg)
  sc = dllcall(InitNew)
  lispbuf = string(4096,CHR(0))
  lispstrptr = dllsptr(lispbuf)
  lispstrend = lispstrptr + 4096 - 1
  dllcall(RtnStr,sc, lispstrptr, lispstrend)
  dllcall(LoadStr, sc, "(display \"Thread 1\")")
  strlen = INSTR(lispbuf, CHR(0))
  PRINT LEFT(lispbuf, strlen - 1),"\n"
  dllcall(Deinit, sc)
END FUNCTION

Output

C:\SB22\TS>scriba Tboot.sb
Thread 1
Thread 2

C:\SB22\TS>
Title: Re: TinyScheme
Post by: JRS on August 28, 2014, 10:39:06 PM
Rob,

Is there any interest in using TinyScheme embedded in SB or are you happy running it as a dedicated Lisp interpreter?

Title: Re: TinyScheme
Post by: JRS on August 28, 2014, 11:23:17 PM
Charles,

I'm trying incorprate the string buffer method for Linux TinyScheme extension module. The results of the  LoadStr() function returns the buffer contents. The following compiled without error but seg. faults when run. (after a bit of os delay) Can you help me with getting the pointers I need in C for the buffer definition?

Code: [Select]
besFUNCTION(TS_load_string) 
  DIM AS scheme PTR sc;
  DIM AS char PTR cmdstr;
  DIM AS char PTR tsbuf[16384];
  besARGUMENTS("iz")
    AT sc, AT cmdstr
  besARGEND
  scheme_set_output_port_string (sc, (int)*tsbuf, (int)*tsbuf + 16383);
  scheme_load_string(sc, cmdstr); 
  besRETURN_STRING(tsbuf);
besEND
Title: Re: TinyScheme
Post by: Charles Pegge on August 28, 2014, 11:34:54 PM
Hi John,

Should it be:

DIM AS char PTR tsbuf[16384];

Also

The casting should be (int*) or, (char*), depending on your function prototype

scheme_set_output_port_string (sc, (int*) tsbuf, (int*) tsbuf + 16383);
Title: Re: TinyScheme
Post by: JRS on August 28, 2014, 11:46:55 PM
Thank you !

How can I trim the buffer string to eliminate the nulls?

Code: [Select]
besFUNCTION(TS_load_string) 
  DIM AS scheme PTR sc;
  DIM AS char PTR cmdstr;
  DIM AS char tsbuf[16384];
  besARGUMENTS("iz")
    AT sc, AT cmdstr
  besARGEND
  scheme_set_output_port_string (sc, (char*) tsbuf, (char*) tsbuf + 16383);
  scheme_load_string(sc, cmdstr); 
  besRETURN_STRING(tsbuf);
besEND
Title: Re: TinyScheme
Post by: Charles Pegge on August 29, 2014, 12:05:36 AM

To return a string trimmed to the right length, you will have to create an SB string copy of the buffer, to the required length. (excluding null terminator for SB strings)



Title: Re: TinyScheme
Post by: RobbeK on August 29, 2014, 12:41:17 AM
Hi John,

Is there any interest in using TinyScheme embedded in SB or are you happy running it as a dedicated Lisp interpreter?

Well, I try to do everything in Lisp, but whatever they tell , for top speed calculus it's better to use something as Oxygen , FB , C etc...  In BigLoo the variadic nature of arithm. operators can be turned off   , p.e. an addition will then take only two arguments.
But it will turn it off for the complete code , a combination (Lisp + C O² ...)  is best I think --
The main problem I had was when using routines that need pointers (as int* p.e.) , but in CL I set them up with Quicklisp now (the cffi) and bigloo has them onboard.  (without these pointers, i will have to do up to million of calls to Oxygen p.e.  , now both Lisp and pe Oxygen share this address and memory can be allocated by Lisp )

best Rob
Didn't do any timing , the exact calculation in CLisp took about a sec. ,  all the others (except BL) did it immediatly.

Title: Re: TinyScheme
Post by: JRS on August 29, 2014, 01:06:51 AM
Quote
To return a string trimmed to the right length, you will have to create an SB string copy of the buffer, to the required length. (excluding null terminator for SB strings)

Too Lazy.

Code: [Select]
besFUNCTION(TS_load_string) 
  DIM AS scheme PTR sc;
  DIM AS char PTR cmdstr;
  DIM AS char tsbuf[16384];
  besARGUMENTS("iz")
    AT sc, AT cmdstr
  besARGEND
  scheme_set_output_port_string (sc, (char*) tsbuf, (char*) tsbuf + 16383);
  scheme_load_string(sc, cmdstr); 
  besRETURN_STRING(rtrim(tsbuf));
besEND

Code: [Select]
' Tiny Scheme - extension module example

DECLARE SUB InitNew ALIAS "TS_init_new" LIB "ts"
DECLARE SUB Deinit ALIAS "TS_deinit" LIB "ts"
DECLARE SUB LoadStr ALIAS "TS_load_string" LIB "ts"

sc = InitNew()
LoadStr(sc, "(load \"init.scm\")")
PRINT LoadStr(sc, "(load \"mbrot2.scm\")"),"\n"
Deinit sc

Output

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ time scriba tsmbrot.sb


Ascii Mandelbrot TinyScheme
---------------------------
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2
1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2
1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3
1 1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3
1 1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3
1 1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3
1 1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4
1 1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4
1 1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4
1 1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4
1 1 1 1111111111111111111111111111111111111111111111117 5 4
1 1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4
1 1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4
1 1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4
1 1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4
1 1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3
1 1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3
1 1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3
1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2
1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2
1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2

real 0m0.661s
user 0m0.656s
sys 0m0.000s
jrs@laptop:~/sb/sb22/sblisp$

SB embedded TinyScheme features:

I'm happy!
Title: Re: TinyScheme
Post by: JRS on August 29, 2014, 02:04:15 AM
Quote from: Rob
Well, I try to do everything in Lisp, but whatever they tell , for top speed calculus it's better to use something as Oxygen , FB , C etc...

Who will be the first to add the 3 needed TinySceme functions to O2 for a BASIC compiler with an embedded Sheme scripting engine?

I thought BASIC was suppose to make stuff easy. Personally I can't type worth a shit so using a language that requires drastically less code and gives me the same results makes sense to me.
Title: Re: TinyScheme
Post by: RobbeK on August 29, 2014, 03:05:47 AM
Hi John,

Yes, but LISP can set up any non-cyclic nested data structures of any dimension - perfect for CAD systems and Graph. Editors like GIMP , it can start mutate itself because it makes no difference between data and code :

from NewLisp :
(println my-program-as-a-string)    ;; prints your code
(eval-string my-program-as-a-string) ;; runs the code

you can write programs mutating themselves , save the mutant and run the mutant -- in the mean time, we can smoke the cigarette and drink the whiskey ...  8)

If you need some teasers for TS -- quickly written :   the reward of the King (story goes when the King asked the inventor of the game of chess about his price ,he answered to start with one grain and double it every next field (rice / corn .. etc ).  The King answered, is that all ?! -- however some calculations learn the amount is immense .....
2 things in the code :   
the named let  --  how to do "pseudo" iterations (the use name "loop" is just another name -- run , do-it etc.. also will do)
how to mark the number is inexact  :  use 1.0 i.o. 1  (otherwise it will run out of capable numbers)

(define (grains x)
   (let loop ((i 1) (j 1.0))
     (display " field ") (display i)
     (display "  number of grains   ")(display j)  (newline)
     (when (< i x) (loop (+ i 1) (* 2 j) ))))

(define (main)
   (display "The reward of the King") (newline)
   (display "----------------------") (newline)
   (newline)
   (grains 64))

------------------------------------------------------------------------------------output

The reward of the King
----------------------

 field 1  number of grains   1
 field 2  number of grains   2
 field 3  number of grains   4
 field 4  number of grains   8
 field 5  number of grains   16
 field 6  number of grains   32
 field 7  number of grains   64
 field 8  number of grains   128
 field 9  number of grains   256
 field 10  number of grains   512
 field 11  number of grains   1024
 field 12  number of grains   2048
 field 13  number of grains   4096
 field 14  number of grains   8192
 field 15  number of grains   16384
 field 16  number of grains   32768
 field 17  number of grains   65536
 field 18  number of grains   131072
 field 19  number of grains   262144
 field 20  number of grains   524288
 field 21  number of grains   1048576
 field 22  number of grains   2097152
 field 23  number of grains   4194304
 field 24  number of grains   8388608
 field 25  number of grains   16777216
 field 26  number of grains   33554432
 field 27  number of grains   67108864
 field 28  number of grains   134217728
 field 29  number of grains   268435456
 field 30  number of grains   536870912
 field 31  number of grains   1073741824
 field 32  number of grains   2147483648
 field 33  number of grains   4294967296
 field 34  number of grains   8589934592
 field 35  number of grains   1.717986918e+010
 field 36  number of grains   3.435973837e+010
 field 37  number of grains   6.871947674e+010
 field 38  number of grains   1.374389535e+011
 field 39  number of grains   2.748779069e+011
 field 40  number of grains   5.497558139e+011
 field 41  number of grains   1.099511628e+012
 field 42  number of grains   2.199023256e+012
 field 43  number of grains   4.398046511e+012
 field 44  number of grains   8.796093022e+012
 field 45  number of grains   1.759218604e+013
 field 46  number of grains   3.518437209e+013
 field 47  number of grains   7.036874418e+013
 field 48  number of grains   1.407374884e+014
 field 49  number of grains   2.814749767e+014
 field 50  number of grains   5.629499534e+014
 field 51  number of grains   1.125899907e+015
 field 52  number of grains   2.251799814e+015
 field 53  number of grains   4.503599627e+015
 field 54  number of grains   9.007199255e+015
 field 55  number of grains   1.801439851e+016
 field 56  number of grains   3.602879702e+016
 field 57  number of grains   7.205759404e+016
 field 58  number of grains   1.441151881e+017
 field 59  number of grains   2.882303762e+017
 field 60  number of grains   5.764607523e+017
 field 61  number of grains   1.152921505e+018
 field 62  number of grains   2.305843009e+018
 field 63  number of grains   4.611686018e+018
 field 64  number of grains   9.223372037e+018

best Rob
Title: Re: TinyScheme
Post by: Mike Lobanovsky on August 29, 2014, 05:17:25 AM
Hi Rob,

Quote from: Rob
you can write programs mutating themselves , save the mutant and run the mutant -- in the mean time, we can smoke the cigarette and drink the whiskey ...

Actually this isn't a LISP-only prerogative. Any interpreter that has its own evaluator function, e.g. ExecString() in FBSL, can do exactly the same. This functionality is inherent in the concept of code interpretation. It effectively means that every interpreter developer is a potential alcoholic and tobacco smoker by definition.

 8)
Title: Re: TinyScheme
Post by: JRS on August 29, 2014, 04:43:28 PM
Rob,

I'm assuming at this point the TinyScheme extension module interface for Script BASIC is code complete. Is there anything you can think of I might of missed that needs to be included? I understand that SB & the TS ext. mod. might not be enough for the type of stuff you do in Lisp. You really should look at O2 and TS as a possible solution. I don't see that connection taking much effort.

John
Title: Re: TinyScheme
Post by: JRS on August 29, 2014, 05:34:30 PM
 I thought I would try your Kings Reward example using the new TinyScheme extension module.

Code: [Select]
' King's Reward
 
IMPORT ts.inc
 
scm = TS_New()
TS_Cmd scm, "(load \"init.scm\")"
reward = """
(define (grains x)
  (let loop ((i 1) (j 1.0))
    (display " field ") (display i)
    (display "  number of grains   ")(display j)  (newline)
    (when (< i x) (loop (+ i 1) (* 2 j) ))))
 
(define (main)
  (display "The reward of the King") (newline)
  (display "----------------------") (newline)
  (newline)
  (grains 64))
(main) 
""" 
PRINT TS_Cmd(scm, reward)
TS_Close scm

Output

jrs@laptop:~/sb/sb22/sblisp/Rob$ time scriba king.sb
The reward of the King
----------------------

 field 1  number of grains   1.0
 field 2  number of grains   2.0
 field 3  number of grains   4.0
...
 field 62  number of grains   2.305843009e+18
 field 63  number of grains   4.611686018e+18
 field 64  number of grains   9.223372037e+18

real   0m0.039s
user   0m0.028s
sys   0m0.008s
jrs@laptop:~/sb/sb22/sblisp/Rob$
Title: Re: TinyScheme
Post by: JRS on August 29, 2014, 10:19:55 PM
Here is the source to the Script BASIC TinyScheme extension module. (using C BASIC)

interface.c
Code: [Select]
// Tiny Scheme - Script BASIC extension module

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include "../../basext.h"
#include "cbasic.h"

#define USE_INTERFACE 1

#include "scheme.h"
#include "scheme-private.h"


/****************************
 Extension Module Functions
****************************/

besVERSION_NEGOTIATE
  RETURN_FUNCTION((int)INTERFACE_VERSION);
besEND

besSUB_START
  DIM AS long PTR p;
  besMODULEPOINTER = besALLOC(sizeof(long));
  IF (besMODULEPOINTER EQ NULL) THEN_DO RETURN_FUNCTION(0);
  p = (long PTR)besMODULEPOINTER;
  RETURN_FUNCTION(0);
besEND

besSUB_FINISH
  DIM AS long PTR p;
  p = (long PTR)besMODULEPOINTER;
  IF (p EQ NULL) THEN_DO RETURN_FUNCTION(0);
  RETURN_FUNCTION(0);
besEND


/***********************
 Tiny Scheme Functions
***********************/

besFUNCTION(TS_init_new)
  DIM AS scheme PTR sc;
  sc = scheme_init_new();
  besRETURN_LONG(sc);
besEND

besFUNCTION(TS_deinit)
  DIM AS scheme PTR sc;
  besARGUMENTS("i")
    AT sc
  besARGEND
  scheme_deinit(sc);
  besRETURNVALUE = NULL;
besEND

besFUNCTION(TS_load_string)
  DIM AS scheme PTR sc;
  DIM AS char PTR cmdstr;
  DIM AS char tsbuf[16384];
  besARGUMENTS("iz")
    AT sc, AT cmdstr
  besARGEND
  scheme_set_output_port_string (sc, (char PTR) tsbuf, (char PTR) tsbuf + 16383);
  scheme_load_string(sc, cmdstr);
  besRETURN_STRING(RTRIM(tsbuf));
besEND

ts.inc
Code: [Select]
' TinyScheme

DECLARE SUB TS_New ALIAS "TS_init_new" LIB "ts"
DECLARE SUB TS_Close ALIAS "TS_deinit" LIB "ts"
DECLARE SUB TS_Cmd ALIAS "TS_load_string" LIB "ts"
Title: Re: TinyScheme
Post by: JRS on August 29, 2014, 11:24:41 PM
Here is The Kings Reward in SB. Call me stupid but the SB code seems to make more sense to me. At least I'm not slow as well.

Code: [Select]
' Kings Reward

grains = 1
PRINT "The reward of the King\n----------------------\n\n"
FOR field = 1 to 64
  PRINT FORMAT("field %g number of grains %d\n", field, grains)
  grains = grains * 2
NEXT

Output

jrs@laptop:~/sb/sb22/sblisp/Rob$ time scriba sbking
The reward of the King
----------------------

field 1 number of grains 1
field 2 number of grains 2
field 3 number of grains 4
...
field 62 number of grains 2305843009213693952
field 63 number of grains 4611686018427387904
field 64 number of grains -9223372036854775808

real   0m0.006s
user   0m0.000s
sys   0m0.004s
jrs@laptop:~/sb/sb22/sblisp/Rob$
Title: Re: TinyScheme
Post by: JRS on August 29, 2014, 11:45:12 PM
Quote from: Rob
how to mark the number is inexact  :  use 1.0 i.o. 1  (otherwise it will run out of capable numbers)

Without Rob's 32 bit hack.

Code: [Select]
' King's Reward

DECLARE SUB InitNew ALIAS "TS_init_new" LIB "ts"
DECLARE SUB Deinit ALIAS "TS_deinit" LIB "ts"
DECLARE SUB LoadStr ALIAS "TS_load_string" LIB "ts"

sc = InitNew()
LoadStr(sc, "(load \"init.scm\")")
reward = """
(define (grains x)
   (let loop ((i 1) (j 1))
     (display " field ") (display i)
     (display "  number of grains   ")(display j)  (newline)
     (when (< i x) (loop (+ i 1) (* 2 j) ))))

(define (main)
   (display "The reward of the King") (newline)
   (display "----------------------") (newline)
   (newline)
   (grains 64))
(main)   
"""   
PRINT LoadStr(sc, reward)
Deinit sc

Output

jrs@laptop:~/sb/sb22/sblisp/Rob$ time scriba king.sb
The reward of the King
----------------------

 field 1  number of grains   1
 field 2  number of grains   2
 field 3  number of grains   4
...
 field 62  number of grains   2305843009213693952
 field 63  number of grains   4611686018427387904
 field 64  number of grains   -9223372036854775808

real   0m0.042s
user   0m0.040s
sys   0m0.000s
jrs@laptop:~/sb/sb22/sblisp/Rob$

@Rob - Would it be worth my time to generate a 64 bit version of this (TinyScheme) for Windows 64 bit?
Title: Re: TinyScheme
Post by: RobbeK on August 30, 2014, 02:13:32 AM
Hi John,

64 bit, yes I think so -- is it a lot of labour ??

the universal Julia , including Mandelbrot

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

(define (julia-primitive i x y rc ic maxit orb)
   (if (or (= i maxit) (> orb 4.0))
       (list i orb)
       (julia-primitive (+ i 1)
                        (+ rc (- (* x x) (* y y)))
                        (+ ic (* 2 x y))
                        rc ic maxit (+ (* x x) (* y y)))))

(define (julia x y rc ic maxit)
  (car (julia-primitive 0 x y rc ic maxit 0)))

(define (mandelbrot x y maxit)
  (car (julia-primitive 0 x y x y maxit 0)))

 
(define (juliaM x y rc ic maxit)
  (julia-primitive 0 x y rc ic maxit 0))

(define (mandelbrotM x y maxit)
  (julia-primitive 0 x y x y maxit 0))

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

be careful , this does more than those found in other languages :
the JuliaM and MandbrotM give back both the iteration level and the orbit in a list (iteration orb).
p.e.
(define result (mandelbrotM x y maxit))
then
(car result) -> iteration level
(cadr result) -> orbit level

this gives more possibilities for research (color schemes etc ...  )

the (Julia ... )  and (Mandelbrot ... ) just give back the iteration level, which is a number

best Rob
Title: Re: TinyScheme
Post by: JRS on August 30, 2014, 08:26:44 AM
Thanks Rob for the iterator +.

I'll give the TinyScheme Windows 64 bit library compile a try. I already have SB 64 bit Windows working. (for some time now)

I would like to work with you on using SDL GFX and the TS engine to create some examples. 

Quote
A worker in southern China was left hanging from 100 feet up the side of a high-rise apartment building when a 10-year-old boy, apparently annoyed at the construction racket outside his window, decided to cut the safety line on the man's rappelling apparatus.

Xinhua says the boy was watching cartoons in his eighth-floor apartment in Guizhou province as the worker was outside installing lighting. So, the boy took a knife and sliced through the rope that allows the worker to move up and down.

According to an English translation of the Xinhua article on the Shanghaiist website, the worker was left dangling midair. He yelled down to a co-worker, who called firemen; he was rescued about 40 minutes later.

I also take funny seriously.

Title: Re: TinyScheme
Post by: JRS on August 30, 2014, 02:44:56 PM
No luck on the 64 bit TinyScheme for Windows. I tried both MinGW and VC12 (VS2013) on Windows 7 64 bit. I'll keep chipping away at it as time permits.

Any interest in using Linux 64 bit?  8)

Title: Re: TinyScheme
Post by: JRS on August 30, 2014, 04:45:41 PM
Rob,

I gave your Mandelbrot iterator a try and after about 15 min. of waiting, I killed the task.  :-\

I guess creating a 16K transfer buffer than  trimming it back to a couple characters per iteration was a bit much. I'm thinking of adding a 3rd optional argument to TS_Cmd() to declare the buffer size you want to use.

Not a good day on the TS front.  :-[

@Anyone: I'm trying to define a character array in C conditionally based on user input. C doesn't seem to like conditional declarations. Any ideas how this might be done?

Title: Re: TinyScheme
Post by: JRS on August 30, 2014, 11:38:23 PM
I think I figured out how to solve my problem. The optional 3rd parameter should be a SB pre-dimensioned string. If not passed, an internal buffer default of 16K will be used. This allows accessing the SB buffer variable in its raw or RTRIM() form.

Code: [Select]
a = STRING(5," ")
b = TS_Cmd(scm, "(+ 2 2)", a)

a = "4    "
b = "4"
Title: Re: TinyScheme
Post by: JRS on August 31, 2014, 08:24:00 AM
My idea was dumb.  >:(

It's still creating the 16K buffer no matter if I pass a SB string to use in its place. I'm leaving it the way it is. If I want a fast Mandelbrot iterator, I'll use my SDL gfx C version of it.

Quote from: Some wise person
Use the right tool for the job.

The Script BASIC TinyScheme extension module source and examples can be found on the C BASIC Bitbucket (https://bitbucket.org/ScriptBasic/c-basic/src/919ed7761481/SBext/TinyScheme/?at=master) site.
Title: Re: TinyScheme
Post by: RobbeK on August 31, 2014, 12:10:37 PM
Hi John,

I'll try to make some time for it this week ,     

"Use the right tool for the job."   --  yep, if all you have is a hammer, everything looks like a nail ...     8)

The Scheme should  be there, to analyze complex structures, run binary trees , very high level abstractions etc ...


best , Rob
Title: Re: TinyScheme
Post by: JRS on August 31, 2014, 12:47:38 PM
Quote
The Scheme should  be there, to analyze complex structures, run binary trees , very high level abstractions etc ...

Yeah, what you said.   ;D
Title: Re: TinyScheme
Post by: JRS on August 31, 2014, 04:54:18 PM
I was finally able to get the Windows 32 bit Script BASIC TinyScheme extension module working. I also had to use a different set of functions for RTRIM. LTRIM and TRIM. I will use these new functions in the Linux ext. modules as well. I'll get this up to the C BASIC Bitbucket site soon. My next adventure is added SDL_gfx as a foreign library function in TS. This will eliminate having to pass result strings back to SB to process.

Code: [Select]
' Character Mandelbrot

IMPORT ts.inc

sc = TS_New()
TS_Cmd sc, "(load \"init.scm\")"
mbrot = """
(newline)
(newline)
(display "Ascii Mandelbrot TinyScheme") (newline)
(display "---------------------------") (newline)

(define sq
   (lambda (x) (* x x)))

(define (1+ x) (+ x 1))
(define (1- x) (- x 1))

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

(define mlevel
   (lambda (L)
     (level 0 (cadr L) (car L) (cadr L) (car L) 11 0)))

(define (main)
   (let ((cnt 0) (lvl 0) (xo -1.7) (yo -2.3) (dz 0.1) )
     (do ((i 0 (1+ i)))
         ((= i 30))
        (do ((j 0 (1+ j)))
            ((= 30 j))
              (set! lvl (mlevel (list (+ xo (* i dz)) (+ yo (* j dz)) )))
              (if (< lvl 10)
                   (begin (display lvl) (display " "))
                   (display lvl))
              (set! cnt (1+ cnt))
              (when (= 30 cnt)
                 (set! cnt 0)
                 (newline))
))))
   
(main)
"""   
PRINT TS_Cmd(sc, mbrot),"\n"
TS_Close sc

Output


C:\SB22\TS>ptime scriba mbrot.sb

ptime 1.0 for Win32, Freeware - http://www.pc-tools.net/
Copyright(C) 2002, Jem Berkes <jberkes@pc-tools.net>

=== scriba mbrot.sb ===
Ascii Mandelbrot TinyScheme
---------------------------
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2
1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2
1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3
1 1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3
1 1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3
1 1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3
1 1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4
1 1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4
1 1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4
1 1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4
1 1 1 1111111111111111111111111111111111111111111111117 5 4
1 1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4
1 1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4
1 1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4
1 1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4
1 1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3
1 1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3
1 1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3
1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2
1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2
1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2


Execution time: 1.027 s

C:\SB22\TS>

Title: Re: TinyScheme
Post by: JRS on August 31, 2014, 05:32:43 PM
TinyScheme Windows 32 Download

Attached is the Script BASIC ts.dll TinyScheme extension module, libtinyscheme.dll library, scheme.exe console interpreter and a couple examples.

.
Title: Re: TinyScheme
Post by: JRS on August 31, 2014, 07:12:59 PM
Rob,

Is there a way you could generate the pixel Mandelbrot points in a TinyScheme list with any delimiter your chose? I would then be able to SPLITA the string to a SB array and generate the Mandelbrot graphic in SDL_gfx.

FYI: I only need the top half of this. I'll memorize the bottom half in Script BASIC. (iterationless)  8)


(http://files.allbasic.info/ScriptBasic/gfx/sbgfxu64_mandelbrot2.png)

Code: [Select]
' ScriptBasic GFX - Mandelbrot

IMPORT gfx.inc

s = gfx::Window(640,480,"ScriptBasic GFX Mandelbrot")
ts = gfx::Time()
FOR y = 0 TO 479
  FOR x = 0 TO 639
    cx = (x - 320) / 120
    cy = (y - 240) / 120
    rit = gfx::Mandelbrot(cx, cy, 510)
    gfx::PixelRGBA s, x, y, rit * 12, rit * 8, rit * 4, 255
  NEXT
NEXT
te = gfx::Time()
gfx::stringColor s, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0x000000ff
gfx::Update
WHILE gfx::KeyName(1) <> "+escape"
WEND
gfx::Close

interface.c (SB GFX ext. module)
Code: [Select]
besFUNCTION(gfx_Mandelbrot)
  DIM AS double cx, cy, zx, zy, tp;
  DIM AS int iter;
  besARGUMENTS("rri")
    AT cx, AT cy, AT iter
  besARGEND
  DEF_WHILE (zx * zx + zy * zy < 4 AND iter > 0)
  BEGIN_WHILE
    tp = zx * zx - zy * zy + cx;
    zy = 2 * zx * zy + cy;
    zx = tp;
    iter = iter - 1;
  WEND
  besRETURN_LONG(iter);
besEND

Quote
Critical orbits of complex numbers

Graphically speaking, a function of the form f (x) = x2 + c (where c is a complex number) is a special function under iteration.  If you plot the results of the iterations (starting at x = 0) in the complex plane, you obtain what is called the critical orbits of c.  If these critical orbits repeat (where the same point in the complex plane repeats), the complex number is in the Mandelbrot set.  If the critical orbits simply move further and further away from the origin, the complex numbers are not in the Mandelbrot set.
Title: Re: TinyScheme
Post by: JRS on August 31, 2014, 08:51:53 PM
If your running on Linux 64 bit, attached is your Script BASIC TinyScheme 64 bit treat.

.
Title: Re: TinyScheme
Post by: JRS on August 31, 2014, 10:02:04 PM
I was able to get a MySQL extension module for TinyScheme working which is helpful for creating the SDL_gfx extension module. Attached is the TinyScheme MySQL library I built if you want to give it a try.

Quote from: Docs
tsx_mysql(1) API Reference tsx_mysql(1)
NAME
 tsx_mysql.so <-> a mysql extension for tiny scheme
SYNOPSIS
 (load-extension "tsx_mysql")
 Load the MySQL extension into the tiny scheme environment.
 (mysql-connect hostname username password database)
 Connect to a MySQL database. This function takes four string
 arguments: hostname, username, password, database.
 (mysql-disconnect)
 Disconnect from a MySQL database.
 (mysql-query sql)
 Query a MySQL database. This function takes a string containing
 SQL statements. The query results will be returned as a list of
 strings.
 (mysql-error)
 Returns the current MySQL error string.
FILES
 tsx_mysql.so
AUTHOR
 A. Carl Douglas (carl.douglas@gmail.com)
tsx_mysql.so 11 July 2011 tsx_mysql(1)


jrs@laptop:~/tinyscheme/tinyscheme-1.41$ ./scheme
TinyScheme 1.41
ts> (load "init.scm")
Loading init.scm
#<EOF>
ts> (load-extension "tsx_mysql")

(display "Mysql extension test.")(newline)

(define queries (list
                  "SELECT VERSION(), CURRENT_DATE"
                  "SHOW DATABASES"
                  "SELECT  table_name, table_type, engine FROM information_schema.tables"))

(define run-query
  (lambda (sql)
    (let ((result (mysql-query sql)))
      (if result
        (display result)
        (display (mysql-error))))
    (newline)))

(if (mysql-connect "" "" "" "")
    (for-each run-query queries)
    (display (mysql-error)))

(mysql-disconnect)
(newline)
#t
ts> Mysql extension test.#t
ts>
#t
ts> queries
ts> run-query
ts> #((5.5.38-0ubuntu0.12.04.1 2014-08-31))
#((information_schema) (test))
#((CHARACTER_SETS SYSTEM VIEW MEMORY) (COLLATIONS SYSTEM VIEW MEMORY) (COLLATION_CHARACTER_SET_APPLICABILITY SYSTEM VIEW MEMORY) (COLUMNS SYSTEM VIEW MyISAM) (COLUMN_PRIVILEGES SYSTEM VIEW MEMORY) (ENGINES SYSTEM VIEW MEMORY) (EVENTS SYSTEM VIEW MyISAM) (FILES SYSTEM VIEW MEMORY) (GLOBAL_STATUS SYSTEM VIEW MEMORY) (GLOBAL_VARIABLES SYSTEM VIEW MEMORY) (KEY_COLUMN_USAGE SYSTEM VIEW MEMORY) (PARAMETERS SYSTEM VIEW MyISAM) (PARTITIONS SYSTEM VIEW MyISAM) (PLUGINS SYSTEM VIEW MyISAM) (PROCESSLIST SYSTEM VIEW MyISAM) (PROFILING SYSTEM VIEW MEMORY) (REFERENTIAL_CONSTRAINTS SYSTEM VIEW MEMORY) (ROUTINES SYSTEM VIEW MyISAM) (SCHEMATA SYSTEM VIEW MEMORY) (SCHEMA_PRIVILEGES SYSTEM VIEW MEMORY) (SESSION_STATUS SYSTEM VIEW MEMORY) (SESSION_VARIABLES SYSTEM VIEW MEMORY) (STATISTICS SYSTEM VIEW MEMORY) (TABLES SYSTEM VIEW MEMORY) (TABLESPACES SYSTEM VIEW MEMORY) (TABLE_CONSTRAINTS SYSTEM VIEW MEMORY) (TABLE_PRIVILEGES SYSTEM VIEW MEMORY) (TRIGGERS SYSTEM VIEW MyISAM) (USER_PRIVILEGES SYSTEM VIEW MEMORY) (VIEWS SYSTEM VIEW MyISAM) (INNODB_BUFFER_PAGE SYSTEM VIEW MEMORY) (INNODB_TRX SYSTEM VIEW MEMORY) (INNODB_BUFFER_POOL_STATS SYSTEM VIEW MEMORY) (INNODB_LOCK_WAITS SYSTEM VIEW MEMORY) (INNODB_CMPMEM SYSTEM VIEW MEMORY) (INNODB_CMP SYSTEM VIEW MEMORY) (INNODB_LOCKS SYSTEM VIEW MEMORY) (INNODB_CMPMEM_RESET SYSTEM VIEW MEMORY) (INNODB_CMP_RESET SYSTEM VIEW MEMORY) (INNODB_BUFFER_PAGE_LRU SYSTEM VIEW MEMORY))
(#t #t)
ts> #t
ts>
#t
ts>



.
Title: Re: TinyScheme
Post by: JRS on September 01, 2014, 08:29:22 AM
I took a peek at the code for the MySQL extension module for TinyScheme and it is similar to the Script BASIC extension module API.

I would like to try the idea of creating pixel / position color value in a TS list and passing it to SB for processing as a first step.
 
@Rob - It doesn't seem that Lisp in BASIC has attracted much interest from anyone other than you and Mike. You have tons of Lisp options from interpreters to compilers to chose from so this reality isn't a surprise. I'm happy where things are currently with the SB TS ext. module (Linux & Windows) and I don't think putting more effort into it would do anything to make it more attractive to anyone other than you. I would be happy to try any suggestions you might have for the SB TS interface but Lisp isn't my main focus.

Title: Re: TinyScheme
Post by: JRS on September 01, 2014, 04:18:42 PM
Rob,

I found a github repository for TinyScheme (fork) that has fixed some issues and included the RE (regular expression) and TSX (TinySchmeme Extensions) extension modules. I couldn't get RE to work so it isn't included in the attached zip. If you could give this a test, that would be great. The tinyscheme.exe was compiled with VS2008 (VC9) and the schme.exe and the libtinyscheme.dll were compiled with TDM-GCC-32. The Script BASIC TinyScheme extension module for Windows 32 seems to work fine with the new libtinyscheme.dll.


Code: [Select]
ts> (load-extension "tsx")
#t
ts> (time)
(114 8 1 17 59 44)
ts> (gettimeofday)
(1409619622 865397)
ts> (file-size "init.scm")
24511
ts> (system "ls -l init.scm")
-rw-rw-r-- 1 jrs jrs 24511 Sep  1 16:45 init.scm
0
ts>


TinyScheme Extensions (TSX) 1.1  [September, 2002]
(c) 2002 Manuel Heras-Gilsanz (manuel@heras-gilsanz.com)

This software is subject to the license terms contained in the
LICENSE file.


TSX FUNCTIONS

TSX incorporates the following functions:

*Sockets (included if HAVE_SOCKETS is defined in tsx.h)

(make-client-socket host port)
        host: string (IP address or host name)
        port: integer number

        Returns a socket which is already connected to the
        specified host and port, or #f if the connection could
        not be performed.

(make-server-socket port)
        port: integer number

        Returns a socket which is bound to the specified port on
        the local machine, and ready to accept connections. If the
        socket could not be created (e.g., because the port is
        already in use, or it is a privileged port and the user has
        no permissions on it), #f is returned.

(recv! sock buff)
        sock: socket obtained with make-client-socket or accept
        buff: string

        Waits for received data through the specified socket, and
        stores it on the buffer. The return value indicates the
        number of received bytes. This call blocks until some data
        is received, but does not guarantee that buff gets
        completely filled. If an error occurs (e.g., the other
        peer disconnects) then #f is returned.

(recv-new-string sock)
        sock: socket obtained with make-client-socket or accept

        Waits for received data through the specified socket, and
        returns it in a new string. This call blocks until some
        data is received. If an error occurs, then #f is returned.

(send sock buff)
        sock: socket obtained with make-client-socket or accept
        buff: string

        Sends the data contained in the string through the socket.
        It returns the number of transmitted bytes (could be
        different than the size of the string!), or #f if an error
        occured (e.g., the other peer disconnected).

(accept server-sock)
        server-sock: socket obtained with make-server-socket

        Waits until a connection is received on the specified
        server socket, and returns the connected socket. If an
        error occurs (e.g., the network interface shuts down), it
        returns #f instead.

(close-socket sock)
        sock: socket obtained with make-server-socket,
              make-client-socket or accept

   The socket is closed. No further calls should be performed
        on this socket.

(sock-is-data-ready? sock)
        sock: socket obtained with make-server-socket,
              make-client-socket or accept

   This function allows non-blocking operation with sockets.
   It returns #t if data is available for reception on this
   socket, and #f if no data has been received.

(sock-peek sock)
        sock: socket obtained with make-server-socket,
              make-client-socket or accept

   This function returns (as a newly created string) the
   data received in this socket. The information is not
   removed from the input queue.

*File system (included if HAVE_FILESYSTEM is defined in tsx.h)

Scheme already defines functions to read and write files. These
functions allow access to the filesystem to check if a certain
file exists, to get its size, etc.

(file-size filename)
        filename: string

        This function returns the size (in bytes) of the
        indicated file, or #f if the file does not exists or
        is not accessible to the requesting user.

(file-exists? filename)
        filename: string

        This function returns #t if the indicated file exists, and
        #f if it does not exists or it is not accessible to the
        requesting user.

(delete-file filename)
        filename: string

        Removes the specified file. It returns #t if the operation
        succeeds, or #f otherwise (e.g., because the file is
        read-only, or because the file does not exist).

(open-dir-stream path)
        path: string

        Opens a "directory stream" on the provided directory path.
        This stream will provide all the files within the directory,
        using the function read-dir-entry. The stream should be closed
        at the end with close-dir-stream.

(read-dir-entry dirstream)
        dirstream: directory stream, obtained with open-dir-stream.

        It returns the name of the following directory entry, or eof
        if all the entries were provided. Check the return value with
        with eof-object?.

(close-dir-stream dirstream)
        dirstream: directory stream, obtained with open-dir-stream.

        Close directory stream. No further calls to read-dir-entry should
        be performed.


*Time (available if HAVE_TIME is defined in tsx.h)

(time)
        Returns the current local time, as a list of integer
        containing:
          (year month day-of-month hour min sec millisec)
        The year is expressed as an offsett from 1900.

(gettimeofday)
        Returns a list containing the number of seconds from
        the beginning of the day, and microseconds within the
        current second.

(usleep microsec)
        microsec: integer

        Suspends execution of the calling thread during the
        specified number of microseconds.


*Miscellaneous functions (available if HAVE_MISC is defined)

(getenv varname)
        varname: string

        Returns a string with the content of the specified
        environment variable, or #f if the variable is not
        defined.

(system command)
        command: string

        Executes a command on the /bin/sh shell. Returns #f if
        it is unable to run /bin/sh or another error occurs,
        or an integer return code which is the value returned
        by the command to the shell.



.
Title: Re: TinyScheme
Post by: RobbeK on September 02, 2014, 12:34:19 AM
Hi John,

I'll have a look at it probably tomorrow, have to finish a (small) job first ...


best Rob
Title: Re: TinyScheme
Post by: JRS on September 02, 2014, 05:57:05 AM
Thanks Rob.

Title: Re: TinyScheme
Post by: RobbeK on September 02, 2014, 06:07:50 AM
Hi John,

In the mean time -- from a few days ago , should work also in TinyScheme (with minor modifications) , code finds a number exact ! solutions of the Riemann Zeta function , it's based on recognizing number patterns.   ( I hope it's correct , otherwise I'll get a number of mathematicians against me  ;)   -- should be an excellent benchmark

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

(define zeta (λ (lim n acc)
  (if (zero? lim) acc
      (zeta (- lim 1) n (+ acc (/ 1.0 (expt lim n)))))))


(define pi-list (λ  (n L)
  (if (zero? n) L
      (pi-list (- n 1) (cons (expt pi n) L)))))

(define almost (λ (x )
  (let (( tst (round x)))
    (if  (< (abs (- x tst)) 0.00001) (round x) 0)
  )))

(define not-zero? (λ (i max L)
  (if (or (= i (- max 1) ) (> (car L) 0)) (list i (car L))
      (not-zero? (+ i 1) max (cdr L)))))

(define iter
   (let (( piL (pi-list 20 '())) (res '()) (solution 0) )
    {λ  (start end)
      (if (= start end) (display "finished")
          (begin
            (let (( x (zeta 1000000 start 0 )))
      (set! res (map (lambda (y) (/ y x)) piL))
      (set! res (map almost res))
      (set! solution (not-zero? 0 (length res) res))
      (when (> (cadr solution) 0)
       (display "Zeta(")
       (display start) (display ") = expt pi ")
       (display (+ 1 (car solution)))
       (display " / ")
       (displayln (cadr solution)) ))
            (iter (+ 1 start) end  )))}))
         


(define   main  (λ ()
  (displayln "Zeta solutions")
  (displayln "--------------")
  (displayln " ")
  (iter 2 12)))

(main)

---------------- you will have to replace the λ  by lambda and define   (define (displayln s) (display s) (newline))

You can compare the speed with compiled (bytecode and GNU Lightning JIT) pro attachment

best Rob
(I wrote the code in a way it is compatible with BL too --   begin replaced with sequence and display to be replaced with print...
)

sorry , lisp ..  means big executables.....  pi should be defined in TS I think ?   

.
Title: Re: TinyScheme
Post by: JRS on September 02, 2014, 07:55:20 AM
Rob,

Please post a version of this that runs on TinyScheme. I not a good enough Lisp programmer to understand your instructions.

Title: Re: TinyScheme
Post by: RobbeK on September 02, 2014, 10:05:22 AM
Sure,

;;-----------------------------------------------------------------------------------------------------------

 

(define pi (* 2 (acos 0)))

(define zeta (lambda (lim n acc)
  (if (zero? lim) acc
      (zeta (- lim 1) n (+ acc (/ 1.0 (expt lim n)))))))


(define pi-list (lambda  (n L)
  (if (zero? n) L
      (pi-list (- n 1) (cons (expt pi n) L)))))

(define almost (lambda (x )
  (let (( tst (round x)))
    (if  (< (abs (- x tst)) 0.00001) (round x) 0)
  )))

(define not-zero? (lambda (i maxx L)
  (if (or (= i (- maxx 1) ) (> (car L) 0)) (list i (car L))
      (not-zero? (+ i 1) maxx (cdr L)))))


         
(define (iter x)
     (let ( ( piL (pi-list 20 '() )) (res '() ) (solution 0))
       (do ((i 2 (+ i 1)))
           ((= i x))
         (let (( x (zeta 1000000 i 0)))
           (set! res (map (lambda (y) (/ y x)) piL))
           (set! res (map almost res))
           (set! solution (not-zero? 0 (length res) res ))
           (when (> (cadr solution) 0)
             (display "Zeta ")
             (display i) (display " = (expt pi ")
             (display (+ 1 (car solution)))
             (display ") / ")
             (display (cadr solution))  (newline) ))))
    (display "finished"))


(newline)
(display "Zeta (probing) TinyScheme" ) (newline)
(display "-------------------------" ) (newline)
(newline)
(iter 12)

;;------------------------------------------------------------------------------------------------------------

of course slower than the DrRacket Scheme

best Rob
Title: Re: TinyScheme
Post by: JRS on September 02, 2014, 10:39:28 AM
Thanks Rob!


jrs@laptop:~/sb/sb22/TS$ time tinyscheme zeta.scm

Zeta (probing) TinyScheme
-------------------------

Zeta 2 = (expt pi 2) / 6.0
Zeta 4 = (expt pi 4) / 90.0
Zeta 6 = (expt pi 6) / 945.0
Zeta 8 = (expt pi 8) / 9450.0
Zeta 10 = (expt pi 10) / 93555.0
finished
real   2m39.188s
user   2m38.518s
sys   0m0.520s
jrs@laptop:~/sb/sb22/TS$


Yes. Your compiled version runs significantly faster.
Title: Re: TinyScheme
Post by: JRS on September 02, 2014, 02:40:08 PM
Rob,

Can you check out the attached TinyScheme compiler/optimizer written in TS and see if it works?
 
Here is another link to a compiler. Scheme to ASM (http://canonical.org/~kragen/sw/urscheme/). Written in Scheme like the above. May not work with TinyScheme.

I gave the ur-scheme compiier a try in MIT/GNU Scheme and it seems to work. I loaded the compiler.scm and started typing in Scheme commands and it converted them to ASM on the fly.

Code: ASM
  1.         # (end of standard library prologue)
  2. (quit)
  3.         # get procedure
  4.         push %eax
  5.         movl (_wlist_14), %eax
  6.         # apply procedure
  7.         call ensure_procedure
  8.         movl 4(%eax), %ebx
  9.         movl $0, %edx
  10.         call *%ebx
  11.         pop %eax
  12. (display (+ 2 2))
  13.         push %eax
  14.         movl $1 + 2<<2, %eax
  15.         push %eax
  16.         movl $1 + 2<<2, %eax
  17.         # inlined integer add
  18.         call ensure_integer
  19.         xchg %eax, (%esp)
  20.         call ensure_integer
  21.         pop %ebx
  22.         add %ebx, %eax
  23.         dec %eax
  24.         # get procedure
  25.         push %eax
  26.         movl (_display_2), %eax
  27.         # apply procedure
  28.         call ensure_procedure
  29.         movl 4(%eax), %ebx
  30.         movl $1, %edx
  31.         call *%ebx
  32.         pop %eax
  33.  

Update: I loaded thet compile.scm (ur-scheme compiler) in TinySchment and it processed the compiler code and returning a T (true). It didn't convert commands I typed in like MIT/GNU Scheme but that was a issue mentioned in the docs about TinyScheme. The other cool thing it support 64 bit and doesn't require any external libraries to execute the code. I'm thinking this could be a neat way to create TinyScheme foreign functions. Charles should take a look at this.
 

.
Title: Re: TinyScheme
Post by: JRS on September 02, 2014, 07:06:53 PM
Here is Ackermann converted to ASM.

Code: [Select]
(define (ack m n)
  (cond ((= m 0) (+ n 1))
        ((= n 0) (ack (- m 1) 1))
        (else (ack (- m 1) (ack m (- n 1))))))

(define (main . args)
  (run-benchmark
    "ack"
    ack-iters
    (lambda (result) (equal? result 4093))
    (lambda (m n) (lambda () (ack m n)))
    3
    9))

        .section .data
_ack_1:
        .long 2 + 256<<2
        .text
        # compute initial value for global variable
        # jump past the body of the lambda
        jmp _ack_2
        .section .rodata
        # align pointers so they end in binary 00
        .align 4
_ack_3:
        .long 0xca11ab1e
        .long _ack_4
        .long 0
        .text
        .type _ack_4, @function
_ack_4:
        # compute desired %esp on return in %ebx and push it
        # the extra offset of 4 skips over the return address
        lea 4(%esp,%edx,4), %ebx
        push %ebx
        push %ebp
        lea 12(%esp), %ebp
        cmpl $2, %edx
        jnz argument_count_wrong
        # discarding useless value in %eax
        pop %eax
        # %ifeq
        push %eax
        movl 0(%ebp), %eax
        push %eax
        movl $1 + 0<<2, %eax
        cmpl %eax, (%esp)
        pop %eax
        pop %eax
        jnz _ack_5
        push %eax
        movl $1 + 1<<2, %eax
        push %eax
        movl 4(%ebp), %eax
        # inlined integer add
        call ensure_integer
        xchg %eax, (%esp)
        call ensure_integer
        pop %ebx
        add %ebx, %eax
        dec %eax
        jmp _ack_6
_ack_5:
        # %ifeq
        push %eax
        movl 4(%ebp), %eax
        push %eax
        movl $1 + 0<<2, %eax
        cmpl %eax, (%esp)
        pop %eax
        pop %eax
        jnz _ack_7
        push %eax
        movl $1 + 1<<2, %eax
        push %eax
        movl $1 + 1<<2, %eax
        push %eax
        movl 0(%ebp), %eax
        # inlined integer subtract
        call ensure_integer
        xchg %eax, (%esp)
        call ensure_integer
        sub %eax, (%esp)
        pop %eax
        inc %eax
        # get procedure
        push %eax
        movl (_ack_1), %eax
        # apply procedure
        # Tail call; nargs = 2
        # Note %esp points at the last thing pushed,
        # not the next thing to push.  So for 1 arg, we want %ebx=%esp
        lea 4(%esp), %ebx
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        push 0(%ebx)
        push -4(%ebx)
        push %edx
        call ensure_procedure
        movl 4(%eax), %ebx
        movl $2, %edx
        jmp *%ebx
        jmp _ack_8
_ack_7:
        push %eax
        movl $1 + 1<<2, %eax
        push %eax
        movl 4(%ebp), %eax
        # inlined integer subtract
        call ensure_integer
        xchg %eax, (%esp)
        call ensure_integer
        sub %eax, (%esp)
        pop %eax
        inc %eax
        push %eax
        movl 0(%ebp), %eax
        # get procedure
        push %eax
        movl (_ack_1), %eax
        # apply procedure
        call ensure_procedure
        movl 4(%eax), %ebx
        movl $2, %edx
        call *%ebx
        push %eax
        movl $1 + 1<<2, %eax
        push %eax
        movl 0(%ebp), %eax
        # inlined integer subtract
        call ensure_integer
        xchg %eax, (%esp)
        call ensure_integer
        sub %eax, (%esp)
        pop %eax
        inc %eax
        # get procedure
        push %eax
        movl (_ack_1), %eax
        # apply procedure
        # Tail call; nargs = 2
        # Note %esp points at the last thing pushed,
        # not the next thing to push.  So for 1 arg, we want %ebx=%esp
        lea 4(%esp), %ebx
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        push 0(%ebx)
        push -4(%ebx)
        push %edx
        call ensure_procedure
        movl 4(%eax), %ebx
        movl $2, %edx
        jmp *%ebx
_ack_8:
_ack_6:
        # procedure epilogue
        # get return address
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        jmp *%edx
        .size _ack_4, .-_ack_4
_ack_2:
        push %eax
        movl $_ack_3, %eax
        # initialize global variable with value
        movl %eax, (_ack_1)
        pop %eax
        .section .data
_main_1:
        .long 2 + 256<<2
        .text
        # compute initial value for global variable
        # jump past the body of the lambda
        jmp _main_2
        .section .rodata
        # align pointers so they end in binary 00
        .align 4
_main_3:
        .long 0xca11ab1e
        .long _main_4
        .long 0
        .text
        .type _main_4, @function
_main_4:
        # make space for variadic argument list
        pop %ebx
        push %ebx
        push %ebx
        # push desired %esp on return
        lea 8(%esp,%edx,4), %ebx
        push %ebx
        push %ebp
        lea 12(%esp), %ebp
        call package_up_variadic_args
        # discarding useless value in %eax
        pop %eax
        push %eax
        movl $1 + 9<<2, %eax
        push %eax
        movl $1 + 3<<2, %eax
        # jump past the body of the lambda
        jmp _main_5
        .section .rodata
        # align pointers so they end in binary 00
        .align 4
_main_6:
        .long 0xca11ab1e
        .long _main_7
        .long 0
        .text
        .type _main_7, @function
_main_7:
        # compute desired %esp on return in %ebx and push it
        # the extra offset of 4 skips over the return address
        lea 4(%esp,%edx,4), %ebx
        push %ebx
        push %ebp
        lea 12(%esp), %ebp
        cmpl $2, %edx
        jnz argument_count_wrong
        # discarding useless value in %eax
        pop %eax
        # move arg from stack to heap: m
        push %eax
        movl 0(%ebp), %eax
        # moving top of stack to newly allocated heap var
        # allocate bytes: 8
        push %eax
        movl (arena_pointer), %eax
        add $8, (arena_pointer)
        cmpl $end_arena, (arena_pointer)
        ja arena_full
        # now %eax points to newly allocated memory
        movl $0x1ce11ed, (%eax)
        pop 4(%eax)
        # move arg from stack to heap: n
        push %eax
        movl 4(%ebp), %eax
        # moving top of stack to newly allocated heap var
        # allocate bytes: 8
        push %eax
        movl (arena_pointer), %eax
        add $8, (arena_pointer)
        cmpl $end_arena, (arena_pointer)
        ja arena_full
        # now %eax points to newly allocated memory
        movl $0x1ce11ed, (%eax)
        pop 4(%eax)
        # jump past the body of the lambda
        jmp _main_8
        .text
        .type _main_9, @function
_main_9:
        # compute desired %esp on return in %ebx and push it
        # the extra offset of 4 skips over the return address
        lea 4(%esp,%edx,4), %ebx
        push %ebx
        push %ebp
        lea 12(%esp), %ebp
        cmpl $0, %edx
        jnz argument_count_wrong
        # fetch artifact from closure: 0 m
        push 12(%eax)
        # fetch artifact from closure: 1 n
        push 16(%eax)
        # discarding useless value in %eax
        pop %eax
        # fetching heap var pointer 1
        push %eax
        movl -20(%ebp), %eax
        # fetch current value from the heap
        movl 4(%eax), %eax
        # fetching heap var pointer 0
        push %eax
        movl -16(%ebp), %eax
        # fetch current value from the heap
        movl 4(%eax), %eax
        # get procedure
        push %eax
        movl (_ack_1), %eax
        # apply procedure
        # Tail call; nargs = 2
        # Note %esp points at the last thing pushed,
        # not the next thing to push.  So for 1 arg, we want %ebx=%esp
        lea 4(%esp), %ebx
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        push 0(%ebx)
        push -4(%ebx)
        push %edx
        call ensure_procedure
        movl 4(%eax), %ebx
        movl $2, %edx
        jmp *%ebx
        # procedure epilogue
        # get return address
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        jmp *%edx
        .size _main_9, .-_main_9
_main_8:
        # allocate bytes: 20
        push %eax
        movl (arena_pointer), %eax
        add $20, (arena_pointer)
        cmpl $end_arena, (arena_pointer)
        ja arena_full
        # now %eax points to newly allocated memory
        movl %eax, %ebx
        movl $0xca11ab1e, (%ebx)
        movl $_main_9, 4(%ebx)
        movl $2, 8(%ebx)
        # fetching heap var pointer 0
        push %eax
        movl -16(%ebp), %eax
        movl %eax, 12(%ebx)
        pop %eax
        # fetching heap var pointer 1
        push %eax
        movl -20(%ebp), %eax
        movl %eax, 16(%ebx)
        pop %eax
        # procedure epilogue
        # get return address
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        jmp *%edx
        .size _main_7, .-_main_7
_main_5:
        push %eax
        movl $_main_6, %eax
        # jump past the body of the lambda
        jmp _main_10
        .section .rodata
        # align pointers so they end in binary 00
        .align 4
_main_11:
        .long 0xca11ab1e
        .long _main_12
        .long 0
        .text
        .type _main_12, @function
_main_12:
        # compute desired %esp on return in %ebx and push it
        # the extra offset of 4 skips over the return address
        lea 4(%esp,%edx,4), %ebx
        push %ebx
        push %ebp
        lea 12(%esp), %ebp
        cmpl $1, %edx
        jnz argument_count_wrong
        # discarding useless value in %eax
        pop %eax
        push %eax
        movl $1 + 4093<<2, %eax
        push %eax
        movl 0(%ebp), %eax
        # get procedure
        push %eax
        movl (_equalP_1), %eax
        # apply procedure
        # Tail call; nargs = 2
        # Note %esp points at the last thing pushed,
        # not the next thing to push.  So for 1 arg, we want %ebx=%esp
        lea 4(%esp), %ebx
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        push 0(%ebx)
        push -4(%ebx)
        push %edx
        call ensure_procedure
        movl 4(%eax), %ebx
        movl $2, %edx
        jmp *%ebx
        # procedure epilogue
        # get return address
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        jmp *%edx
        .size _main_12, .-_main_12
_main_10:
        push %eax
        movl $_main_11, %eax
        push %eax
        movl (_main_13), %eax
        .section .rodata
        # align pointers so they end in binary 00
        .align 4
_main_14:
        .long 0xbabb1e
        .long 3
        .ascii "ack"
        .text
        push %eax
        movl $_main_14, %eax
        # get procedure
        push %eax
        movl (_main_15), %eax
        # apply procedure
        # Tail call; nargs = 6
        # Note %esp points at the last thing pushed,
        # not the next thing to push.  So for 1 arg, we want %ebx=%esp
        lea 20(%esp), %ebx
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        push 0(%ebx)
        push -4(%ebx)
        push -8(%ebx)
        push -12(%ebx)
        push -16(%ebx)
        push -20(%ebx)
        push %edx
        call ensure_procedure
        movl 4(%eax), %ebx
        movl $6, %edx
        jmp *%ebx
        # procedure epilogue
        # get return address
        movl -4(%ebp), %edx
        movl -8(%ebp), %esp
        movl -12(%ebp), %ebp
        jmp *%edx
        .size _main_4, .-_main_4
_main_2:
        push %eax
        movl $_main_3, %eax
        # initialize global variable with value
        movl %eax, (_main_1)
        pop %eax
Title: Re: TinyScheme
Post by: JRS on September 02, 2014, 09:54:41 PM
I created a set of TinyScheme test scripts from the urscheme compiler distribution. Attached is the .scm scripts and the Script BASIC script to run them.

Code: Text
  1. jrs@laptop:~/tinyscheme/urscheme-3$ time scriba TS-test.sb > TS-test.out
  2.  
  3. real    0m2.673s
  4. user    0m2.664s
  5. sys     0m0.004s
  6. jrs@laptop:~/tinyscheme/urscheme-3$ ls test.*
  7. test.append.scm          test.cons.scm           test.fib.scm            test.map.scm            test.quadruple.scm      test.string2symbol.scm
  8. test.assq.scm            test.crufty.scm         test.firstclassops.scm  test.memq.scm           test.quote.scm          test.stringappend.scm
  9. test.case.scm            test.definelist.scm     test.funkyid.scm        test.negative.scm       test.quotient.scm       test.stringlength.scm
  10. test.charalpha.scm       test.doubledefine.scm   test.implicitbegin.scm  test.niladic.scm        test.remainder.scm      test.symbol2string.scm
  11. test.charint.scm         test.emptyvariadic.scm  test.lessthan.scm       test.number2string.scm  test.reverse.scm        test.tailcall.scm
  12. test.charwhitespace.scm  test.equal.scm          test.let.scm            test.or.scm             test.set.scm            test.variadic.scm
  13. test.closure.scm         test.eqv.scm            test.list2string.scm    test.out                test.simplestring.scm   test.write.scm
  14. test.cond.scm            test.fib2.scm           test.literalchar.scm    test.predicates.scm     test.string2number.scm
  15.  


.
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 03, 2014, 12:30:04 AM
Hi John,

This thingy looks very neat and according to the dev's report, it works much faster than its compatibles and it yields significantly denser machine code output.

But it has one very important weakness: it doesn't support floating-point maths, which renders it impractical for everyday use. It needs much more work on the asm side of its engine. LISP language pattern recognition is already there and fixed-point asm translation too but the equivalent floating-point translation blocks remain yet to be developed.

In all other respects, this material is very instructive. Thanks for sharing.
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 03, 2014, 01:22:54 AM
Quote from: John
compiler.ss.zip (25.82 kB - downloaded 1 times.)

John,

Where are all the other parts of this compiler package? There should be other scripts to match it with:

match.ss
helpers.ss
driver.ss
fmts.pretty
wrapper.ss


and also a tests.ss integrity and regression test script.

This doesn't look like the ur-scheme compiler that you've pointed to in your message. Where does it come from then?
Title: Re: TinyScheme
Post by: JRS on September 03, 2014, 05:53:51 AM
Quote
Where are all the other parts of this compiler package?

Good question! The author only posted the compiler and mentioned the other files weren't included.  :-\

I then moved on to urscheme which seems incomplete on the functionality level. I was able to get the compiler to compile and the first test.append.scm with Chicken Scheme and MIT/GNU Scheme. That is where I left it last night. This is WAY over my head and I'm glad you have shown some interest in this for the Lisp in BASIC projects.

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 03, 2014, 06:45:20 AM
This is WAY over my head and I'm glad you have shown some interest in this for the Lisp in BASIC projects.

Hi John,

Nooooo, it's darn simple once you get the feeling of it. It's much simpler than BASIC. It's only half a dozen keywords like car or cdr or let and all the rest of the language can be built right from these ones! :D

So, John, I've suddenly lost all interest in Lisp-in-Basic. It doesn't have to be so complicated at all and I don't want to waste my time on it any more. I can write my own Scheme JIT compiler right away instead. And this is what I'm going to do in the coming few days.

I'll post here the SBLisp proto shortly as promised and I'll also post the FBLisp code as I have it now on the FBSL forum. FBLisp has some enhancements that are making it 30% faster than SBLisp but unfortunately I can't port them to SB, sorry.

And there won't be any OxyLISP from me either because I now consider this approach to be a dead end. I've better things in mind now. :)

Yet the experience has been really entertaining and instructive.
Title: Re: TinyScheme
Post by: JRS on September 03, 2014, 07:02:26 AM
Quote
Yet the experience has been really entertaining and instructive.

That was the whole point of that project. I think we all can say that the time spent was worth the effort. I would of never did the TinyScheme ext. module. if it wasn't for SBLisp.

Title: TinyScheme Windows 64 w/TSX
Post by: JRS on September 03, 2014, 05:32:28 PM
Good News!

I was able to compile the TinySheme.exe and TSX.dll for Windows 64 bit using VC12 (VS2013).

Let me know if you can now see big numbers.

I gave the King's Reward a try but it wouldn't go beyond 32 fields and displayed zeros from then on. Windows sucks! Same results under Wine 64 bit.


jrs@laptop:~/.wine/drive_c/TS/TS64$ file tinyscheme.exe
tinyscheme.exe: PE32+ executable (console) x86-64, for MS Windows
jrs@laptop:~/.wine/drive_c/TS/TS64$ file tsx.dll
tsx.dll: PE32+ executable (DLL) (GUI) x86-64, for MS Windows


Maybe Mike would have better luck. Windows 64 bit is an unpredictable lonely place.

FYI - Here is the official TinyScheme logo.

(http://files.allbasic.info/TS/ts.png)


.
Title: Re: TinyScheme
Post by: JRS on September 04, 2014, 05:45:29 PM
Can someone confirm there is either a problem with MS 64 bit or TinyScheme compiled under it? Is this strictly a large number multiplication issue or does it go deeper than that?  Call me paranoid but using a 32 bit compiler to compile 64 bit code seems FU.

@Charles - Can you create a Kings Reward in O2 as a 64 bit application and verify Windows 64 bit math works?
Title: Re: TinyScheme
Post by: JRS on September 04, 2014, 06:10:32 PM
I just tested the 64 bit Windows SB version of Kings Reward and it seems to have a similar problem. Must be MS VC12. This same program works fine on Linux to 64 fields.

Code: [Select]
' Kings Reward

grains = 1
PRINT "The reward of the King\n----------------------\n\n"
FOR field = 1 to 64
  PRINT FORMAT("field %g number of grains %d\n", field, grains)
  grains = grains * 2
NEXT

Code: [Select]
C:\sb22_64\TS>scriba king.sb
The reward of the King
----------------------

field 1 number of grains 1
field 2 number of grains 2
field 3 number of grains 4
field 4 number of grains 8
field 5 number of grains 16
field 6 number of grains 32
field 7 number of grains 64
field 8 number of grains 128
field 9 number of grains 256
field 10 number of grains 512
field 11 number of grains 1024
field 12 number of grains 2048
field 13 number of grains 4096
field 14 number of grains 8192
field 15 number of grains 16384
field 16 number of grains 32768
field 17 number of grains 65536
field 18 number of grains 131072
field 19 number of grains 262144
field 20 number of grains 524288
field 21 number of grains 1048576
field 22 number of grains 2097152
field 23 number of grains 4194304
field 24 number of grains 8388608
field 25 number of grains 16777216
field 26 number of grains 33554432
field 27 number of grains 67108864
field 28 number of grains 134217728
field 29 number of grains 268435456
field 30 number of grains 536870912
field 31 number of grains 1073741824
field 32 number of grains -2147483648
field 33 number of grains -2147483648
field 34 number of grains -2147483648
field 35 number of grains -2147483648
field 36 number of grains -2147483648
field 37 number of grains -2147483648
field 38 number of grains -2147483648
field 39 number of grains -2147483648
field 40 number of grains -2147483648
field 41 number of grains -2147483648
field 42 number of grains -2147483648
field 43 number of grains -2147483648
field 44 number of grains -2147483648
field 45 number of grains -2147483648
field 46 number of grains -2147483648
field 47 number of grains -2147483648
field 48 number of grains -2147483648
field 49 number of grains -2147483648
field 50 number of grains -2147483648
field 51 number of grains -2147483648
field 52 number of grains -2147483648
field 53 number of grains -2147483648
field 54 number of grains -2147483648
field 55 number of grains -2147483648
field 56 number of grains -2147483648
field 57 number of grains -2147483648
field 58 number of grains -2147483648
field 59 number of grains -2147483648
field 60 number of grains -2147483648
field 61 number of grains -2147483648
field 62 number of grains -2147483648
field 63 number of grains -2147483648
field 64 number of grains -2147483648

C:\sb22_64\TS>

 
Title: Re: TinyScheme
Post by: Charles Pegge on September 04, 2014, 07:30:22 PM
Hi John,

The only problem in o2 64 bit is the negative sign in the final result.

This can be resolved by using the extended type

Code: [Select]

% filename "t.exe"

includepath "$/inc/"
include "RTL64.inc"
include "console.inc"

' Kings Reward

sys grains = 1
PRINT "The reward of the King"
FOR field = 1 to 64
  PRINTL "field number of grains " & field & ", " & grains
  grains = grains * 2
NEXT

waitkey

/*
The reward of the King
field number of grains 1, 1
field number of grains 2, 2
field number of grains 3, 4
field number of grains 4, 8
field number of grains 5, 16
field number of grains 6, 32
field number of grains 7, 64
field number of grains 8, 128
field number of grains 9, 256
field number of grains 10, 512
field number of grains 11, 1024
field number of grains 12, 2048
field number of grains 13, 4096
field number of grains 14, 8192
field number of grains 15, 16384
field number of grains 16, 32768
field number of grains 17, 65536
field number of grains 18, 131072
field number of grains 19, 262144
field number of grains 20, 524288
field number of grains 21, 1048576
field number of grains 22, 2097152
field number of grains 23, 4194304
field number of grains 24, 8388608
field number of grains 25, 16777216
field number of grains 26, 33554432
field number of grains 27, 67108864
field number of grains 28, 134217728
field number of grains 29, 268435456
field number of grains 30, 536870912
field number of grains 31, 1073741824
field number of grains 32, 2147483648
field number of grains 33, 4294967296
field number of grains 34, 8589934592
field number of grains 35, 17179869184
field number of grains 36, 34359738368
field number of grains 37, 68719476736
field number of grains 38, 137438953472
field number of grains 39, 274877906944
field number of grains 40, 549755813888
field number of grains 41, 1099511627776
field number of grains 42, 2199023255552
field number of grains 43, 4398046511104
field number of grains 44, 8796093022208
field number of grains 45, 17592186044416
field number of grains 46, 35184372088832
field number of grains 47, 70368744177664
field number of grains 48, 140737488355328
field number of grains 49, 281474976710656
field number of grains 50, 562949953421312
field number of grains 51, 1125899906842624
field number of grains 52, 2251799813685248
field number of grains 53, 4503599627370496
field number of grains 54, 9007199254740992
field number of grains 55, 18014398509481984
field number of grains 56, 36028797018963968
field number of grains 57, 72057594037927936
field number of grains 58, 14411518807585587
field number of grains 59, 28823037615171174
field number of grains 60, 57646075230342349
field number of grains 61, 1.152921504606847E+18
field number of grains 62, 2.305843009213694E+18
field number of grains 63, 4.6116860184273879E+18
field number of grains 64, -9.2233720368547758E+18
*/
Title: Re: TinyScheme
Post by: JRS on September 04, 2014, 08:06:47 PM
I'm on Windows 7 64 at the moment and just tried a TDM-GCC-64 compiled version of SB and it has the same issue. I wonder what a 64 bit C version would do.

I noticed O2 goes exponential expression at 61 fields. SB Linux goes integer to the end.

Code: Script BASIC
  1. a = 100000000000
  2. PRINT "100000000000 = ",a,"\n"
  3.  


C:\sb22_64\TS>scriba bignum.sb
100000000000 = -2147483648

C:\sb22_64\TS>


I even tried to print the HEX of a but got the same results.  :(


@Charles - What do you think SB & TinyScheme issue is?
Title: Re: TinyScheme
Post by: Charles Pegge on September 04, 2014, 10:42:53 PM

Does SB use long long?

This, and pointers  are the only 64bit integers, int and long int are 32 bit, under Windows OS's.

There is a table towards the end:
http://en.wikipedia.org/wiki/64-bit_computing
Title: Re: TinyScheme
Post by: JRS on September 04, 2014, 11:42:01 PM
The New Data Types (http://msdn.microsoft.com/en-us/library/ff564619.aspx)

I'm changing my longs to long64 for the 64 bit Windows version of TinyScheme. If it works there then I will do the same for a custom version of SB.

Update:

Using the above 64 bit MS new types TinyScheme compiled okay. Still the same problem though.

Good-night.


Title: Re: TinyScheme
Post by: JRS on September 05, 2014, 07:59:44 AM
Mike,

Do you have time to give the TinyScheme library a compile on Windows 64 bit? I'm miffed why this isn't working.

TIA

John
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 05, 2014, 08:02:14 AM
John,

You should also be aware that there are differences between Windows and Linux' formating placeholders for the C language printf() function used to emulate BASIC's PRINT. For example, the Windows msvcrt.dll which SB is linked against under 32 bits doesn't understand a Linuxoid ll or LL prefix to %d or %u to print a 64-bit signed or unsigned long long integer. So %I64d or %I64u must be used instead of Linuxoid %lld or %llu, respectively.

I am not 100% sure but similar restrictions may apply to integers and floats under 64 bits too. If you don't observe proper formating prefixes in your source code under 32 bits, you will always get a signed value printed where you'd expect its unsigned analog. Perhaps you're seeing a similar side effect but this time under your 64 bits. This needs further investigation.
Title: Re: TinyScheme
Post by: JRS on September 05, 2014, 08:08:51 AM
Good info Mike!

Before I even look at SB's issues on Windows 64 bit, TinySheme is my target at this point. If we can get that working correctly then SB will have a path to follow. Any help you can provide to get us by this, it would be greatly appreciated.

If I remember correctly there were only a couple 64 bit long problems with the SB extension modules but SB core seemed to work out of the box with just compiler switches. (Linux)

John
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 05, 2014, 08:24:40 AM
The problem I'm talking about concerns the printf() function alone. It doesn't pertain to 64-bit SB being generally compilable under Linux and Windows or not. The differences may be platform specific to the C languages and dynamic libraries used on the respective platform. At any rate, the printf() format is hardcoded in your sources as a string so the compiler wouldn't check or correct it for you automatically. This is your responsibility to give the platform dependent runtime library a proper format string for BASIC's PRINT (or TS' (display), for that matter) to behave as expected on both platforms.
Title: Re: TinyScheme
Post by: JRS on September 05, 2014, 08:29:26 AM
I understand what you're saying now. I'll have another peek at scheme.c for printf() format options.
Title: Re: TinyScheme
Post by: JRS on September 05, 2014, 12:25:37 PM
Success!

I got it to work partially listening to what Charles and Mike suggested.

That's it. I still need to do the TSX TinyScheme extension DLL but things are looking up. I'll post a beta after a little more testing.

I got some warnings about 64 bit integers being mapped to standard integers and will convert them in the next round and see if it still works.


scheme.c(2691) : warning C4244: '=' : conversion from '__int64' to 'int', possible loss of data



C:\TS-64>tinyscheme king.scm
The reward of the King
----------------------

 field 1  number of grains   1
 field 2  number of grains   2
 field 3  number of grains   4
 field 4  number of grains   8
 field 5  number of grains   16
 field 6  number of grains   32
 field 7  number of grains   64
 field 8  number of grains   128
 field 9  number of grains   256
 field 10  number of grains   512
 field 11  number of grains   1024
 field 12  number of grains   2048
 field 13  number of grains   4096
 field 14  number of grains   8192
 field 15  number of grains   16384
 field 16  number of grains   32768
 field 17  number of grains   65536
 field 18  number of grains   131072
 field 19  number of grains   262144
 field 20  number of grains   524288
 field 21  number of grains   1048576
 field 22  number of grains   2097152
 field 23  number of grains   4194304
 field 24  number of grains   8388608
 field 25  number of grains   16777216
 field 26  number of grains   33554432
 field 27  number of grains   67108864
 field 28  number of grains   134217728
 field 29  number of grains   268435456
 field 30  number of grains   536870912
 field 31  number of grains   1073741824
 field 32  number of grains   2147483648
 field 33  number of grains   4294967296
 field 34  number of grains   8589934592
 field 35  number of grains   17179869184
 field 36  number of grains   34359738368
 field 37  number of grains   68719476736
 field 38  number of grains   137438953472
 field 39  number of grains   274877906944
 field 40  number of grains   549755813888
 field 41  number of grains   1099511627776
 field 42  number of grains   2199023255552
 field 43  number of grains   4398046511104
 field 44  number of grains   8796093022208
 field 45  number of grains   17592186044416
 field 46  number of grains   35184372088832
 field 47  number of grains   70368744177664
 field 48  number of grains   140737488355328
 field 49  number of grains   281474976710656
 field 50  number of grains   562949953421312
 field 51  number of grains   1125899906842624
 field 52  number of grains   2251799813685248
 field 53  number of grains   4503599627370496
 field 54  number of grains   9007199254740992
 field 55  number of grains   18014398509481984
 field 56  number of grains   36028797018963968
 field 57  number of grains   72057594037927936
 field 58  number of grains   144115188075855872
 field 59  number of grains   288230376151711744
 field 60  number of grains   576460752303423488
 field 61  number of grains   1152921504606846976
 field 62  number of grains   2305843009213693952
 field 63  number of grains   4611686018427387904
 field 64  number of grains   -9223372036854775808

C:\TS-64>
Title: Re: TinyScheme
Post by: JRS on September 05, 2014, 02:04:20 PM
Mike,

I have attached the VC12 output from the compile of scheme.c and the source. Can you have a peek and let me know your recommendation for dealing with these warnings?

John

.
Title: TinyScheme - Windows 64 bit download
Post by: JRS on September 05, 2014, 02:17:27 PM
This version passed the King's Reward test but hasn't address warnings yet.

Rob,

Can you start your testing and try working with large numbers beyond the scope of 32 bit?

Thanks!



.
Title: Re: TinyScheme
Post by: Charles Pegge on September 05, 2014, 03:06:50 PM
Based on examples/math/BCDMul.o2bas

Code: [Select]
'
'================================
'MONSTROUS INTEGER MULTIPLICATION
'================================

'------------------------------------------------------
function multiply(ia as string, ib as string) as string
'======================================================

dim as string a,b,c,d
dim as long pa,pb,pc,pd,la,lb,lc,ld
dim as long nd,sh,qa

a=ia
b=ib
la=len a
lb=len b
lc=la+lb'+10
ld=lc'+20
c=nuls lc 'LINE ACCUMULATOR
d=nuls ld 'BLOCK ACCUMULATOR
pa=*a
pb=*b
pc=*c
pd=*d


pushad



'SETUP POINTERS
'==============

mov esi,pa : add esi,la
mov edi,pb : add edi,lb
mov edx,pc : add edx,lc
mov ebx,pa


mov qa,esi 'RIGHT START POSITION FOR NUMBER A
mov nd,edi 'SETUP NEXT DIGIT POINTER (B NUMBER)
mov sh,edx 'SETUP POSITION SHIFT POINTER



'CONVERT FROM ASCII TO BINARY CODED DECIMAL
'==========================================


mov edi,pa
mov ecx,la
(
 dec ecx
 jl exit
 sub byte [edi],48
 inc edi
 repeat
)
mov edi,pb
mov ecx,lb
(
 dec ecx : jl exit
 sub byte [edi],48
 inc edi
 repeat
)



nextline:
'========

'MULTIPLY BY ONE DIGIT
'WORKING FROM RIGHT TO LEFT

dec edi
mov cl,[edi]
mov ch,0
(
  dec esi
  cmp esi,ebx : jl exit
  mov al,[esi]
  mov ah,0
  mul cl
  add al,ch 'ADD CARRY VALUE
  mov ch,0  'CLEAR CARRY VALUE
  (
    cmp al,10
    jl exit   'NO CARRY
    mov ch,10 'DIVISOR
    div ch    '
    mov ch,al 'CARRY VAL IN CH
    mov al,ah 'REMAINDER NOW IN AL
  )
  dec edx
  mov [edx],al
  repeat
)
'FINAL CARRY
(
  cmp ch,0
  jz exit
  dec edx
  mov [edx],ch
)

'ADD TO BLOCK ACCUMULATOR
'========================

mov esi,pc : add esi,lc
mov edi,pd : add edi,ld
mov ah,0
mov ebx,pc


'BCD ADDITION
'
'WORKING FROM RIGHT TO LEFT

(
  dec esi
  cmp esi,ebx : jl exit
  dec edi
  mov al,0
  xchg al,[esi] 'LOAD AND THEN CLEAR LINE DIGIT
  mov cl,[edi]
  add al,ah 'PREVIOUS CARRY
  add al,cl 'OPERAND
  (
   mov ah,0
   cmp al,10 : jl exit
   sub al,10
   inc ah
  )
  mov [edi],al
  repeat
)


mov ebx,pa

mov esi,qa  'START POSITION FOR NUMBER A

mov edi,nd 'NEXT DIGIT IN NUMBER B
dec edi
mov nd,edi

cmp edi,pb : jle fwd done

'SHIFT OUTPUT TO LINE ACCUM

mov edx,sh
dec edx
mov sh,edx


jmp long nextline



done:



'CONVERT FROM BCD TO ASCII
'=========================


mov edi,pd
mov ecx,ld
add ecx,edi
(
 cmp edi,ecx : jge exit
 add byte [edi],48 : inc edi
 repeat
)



'TRIM LEADING ZEROS
'==================


mov edi,pd
mov ecx,ld
add ecx,edi
(
 cmp edi,ecx : jge exit
 mov al,[edi]
 inc edi
 cmp al,48 : jg exit
 repeat
)
sub edi,pd
mov nd,edi


popad

function=mid(d,nd,ld)

end function


=====
'MAIN
=====


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

'https://defuse.ca/big-number-calculator.htm

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

dim as string a,b,ans

a="1"
for i=1 to 10000
a=multiply(a,"2")
next

cr=chr(13,10)
t="2^" i-1 "=" cr a cr
print t
putfile "t.txt",t

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


Result:
Code: [Select]
2^10000=
19950631168807583848837421626835850838234968318861924548520089498529438830221946631919961684036194597899331129423209124271556491349413781117593785932096323957855730046793794526765246551266059895520550086918193311542508608460618104685509074866089624888090489894838009253941633257850621568309473902556912388065225096643874441046759871626985453222868538161694315775629640762836880760732228535091641476183956381458969463899410840960536267821064621427333394036525565649530603142680234969400335934316651459297773279665775606172582031407994198179607378245683762280037302885487251900834464581454650557929601414833921615734588139257095379769119277800826957735674444123062018757836325502728323789270710373802866393031428133241401624195671690574061419654342324638801248856147305207431992259611796250130992860241708340807605932320161268492288496255841312844061536738951487114256315111089745514203313820202931640957596464756010405845841566072044962867016515061920631004186422275908670900574606417856951911456055068251250406007519842261898059237118054444788072906395242548339221982707404473162376760846613033778706039803413197133493654622700563169937455508241780972810983291314403571877524768509857276937926433221599399876886660808368837838027643282775172273657572744784112294389733810861607423253291974813120197604178281965697475898164531258434135959862784130128185406283476649088690521047580882615823961985770122407044330583075869039319604603404973156583208672105913300903752823415539745394397715257455290510212310947321610753474825740775273986348298498340756937955646638621874569499279016572103701364433135817214311791398222983845847334440270964182851005072927748364550578634501100852987812389473928699540834346158807043959118985815145779177143619698728131459483783202081474982171858011389071228250905826817436220577475921417653715687725614904582904992461028630081535583308130101987675856234343538955409175623400844887526162643568648833519463720377293240094456246923254350400678027273837755376406726898636241037491410966718557050759098100246789880178271925953381282421954028302759408448955014676668389697996886241636313376393903373455801407636741877711055384225739499110186468219696581651485130494222369947714763069155468217682876200362777257723781365331611196811280792669481887201298643660768551639860534602297871557517947385246369446923087894265948217008051120322365496288169035739121368338393591756418733850510970271613915439590991598154654417336311656936031122249937969999226781732358023111862644575299135758175008199839236284615249881088960232244362173771618086357015468484058622329792853875623486556440536962622018963571028812361567512543338303270029097668650568557157505516727518899194129711337690149916181315171544007728650573189557450920330185304847113818315407324053319038462084036421763703911550639789000742853672196280903477974533320468368795868580237952218629120080742819551317948157624448298518461509704888027274721574688131594750409732115080498190455803416826949787141316063210686391511681774304792596709376
Title: Re: TinyScheme
Post by: JRS on September 05, 2014, 03:11:23 PM
Very cool Charles.

I remember you doing something in BCD math for the MD5 / SP Pro time function in SB. I may have another peek at that code after the above example.  8)
Title: Re: TinyScheme
Post by: JRS on September 05, 2014, 05:51:48 PM
I found another Scheme tutorial that might be helpful to Lisp newbies like me.

The Scheme Programming Language (http://www.scheme.com/tspl3/) (Book Online)
Title: Re: TinyScheme
Post by: JRS on September 05, 2014, 10:39:48 PM
Charles / Mike,

I'm trying to understand these warning messages of downgrading my integers. I wonder did I get long long happy and screw up everything else? The following is a good example of a C function creating a mismatch of types.

Code: C
  1. static num num_mod(num a, num b) {
  2.  num ret;
  3.  long e1, e2, res;
  4.  ret.is_fixnum=a.is_fixnum && b.is_fixnum;
  5.  e1=num_ivalue(a);
  6.  e2=num_ivalue(b);
  7.  res=e1%e2;
  8.  /* modulo should have same sign as second operand */
  9.  if (res * e2 < 0) {
  10.     res += e2;
  11.  }
  12.  ret.value.ivalue=res;
  13.  return ret;
  14. }
  15.  

Making e1, e2, res a long long makes res complain of a type mismatch. I can't seem to get around this.

Title: Re: TinyScheme
Post by: RobbeK on September 06, 2014, 12:47:08 AM
Hi John,

And the idea to embed NewLisp ??     (there're libs for Linux and Mac too )

"newLISP is a Lisp-like, general-purpose scripting language. It is especially well-suited for applications in AI, simulation, natural language processing, big data, machine learning and statistics. Because of its small resource requirements, newLISP is excellent for embedded systems applications. Most of the functions you will ever need are already built in. This includes networking functions, support for distributed and multicore processing, and Bayesian statistics."

Attached , I embedded it into GFA (the German IBM which went down around a decade ago -- the compiler is abandonware for the moment (seems, no one claims it).   -- ( a good compiler, producing native code , and allows in-line assembler)  - it has no big numbers , but here they are borrowed from NewLisp.

(for fun : the 128 x does 2 chess boards)
source is in the html file

best Rob


.
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 06, 2014, 04:07:13 AM
I'm trying to understand these warning messages of downgrading my integers.

Hi John,

It seems you're getting conflicts between the capacity of your locals redefined by you as (signed) long long's and that of Scheme's definitions and/or typification of ret and num structures and num_ivalue() function.

You haven't appended the TS header file but judging by your warnings, TS numbers are defined as unsigned long long's whose data capacity in positive numbers is greater than in a (signed) long long. IMO this is where most of your warnings are coming from. You aren't downgrading your integers, you are downgrading Tiny Scheme's.

Try to define your locals as unsigned long long's, recompile, and see what happens.
Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 07:47:47 AM
I attached the complete TinyScheme source a few posts back, did you see it? Would you like me to repost it again? 

If your unable to help, it compiled (with warnings) and I'll leave it at that. This was for Rob not me.

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 06, 2014, 08:00:25 AM
I attached the complete TinyScheme source a few posts back...
If your unable to help...

John, if you mean this post (http://www.oxygenbasic.org/forum/index.php?topic=1185.msg11191#msg11191) then I'm telling you again there's no header file in it, and please stop making fool of me. I can't mend your socks until you take them off and hand them over.
Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 08:07:02 AM
Sorry Mike!

I swear I posted the complete source zip. Here is the URL to the project I'm using.

https://github.com/ignorabimus/tinyscheme



Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 11:05:18 AM
Quote from: Rob
And the idea to embed NewLisp ??

That is pretty cool to see that kind if precision from a 32 bit app. COM also keeps the effort in the 32 bit world. Nice to see it work on Wine even with a OCX requirement.

 

.
Title: Re: TinyScheme
Post by: RobbeK on September 06, 2014, 11:59:46 AM
Hi John,

The GFA compiler is not bad at all -- 
(I have a slight problem under Wine , when running the kind of programs as attached -- after a while the active window darkens as if something is hanging -- I wonder, this can be fixed  -- )

It's the Mandelbrot changing from z² to z³ , ....   this can not be calculated with real numbers -- I used DeMoivre"s Cis function to calculate things.   --- it several moments, one can see the fractal tearing (such things should be done on Riemann surfaces I think to be representable  ::) 

to be honnest , oxygen does it faster -- needing around 2/3 of GFA's benchmark ...

best, Rob
(ps , Wine has some nice themes nowadays -- some looking better than the original window gadget  8) )

in the animation , much time is spent calculating the gradient inside the fract.  --  it is of the form log(log(A)) , this takes a lot of time   to calculate




.
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 06, 2014, 12:20:19 PM
John,

Here's your pair of socks. Each directory contains a VS2013 solution, a precompiled release executable, and Rob's scripts to test. Regex and tcx (whatever that is) aren't included in the solutions. Note the tiny size of exes vs. the one that you posted here.

No changes to the original sources were necessary. They compiled in both 32 and 64 bits out of the box.

Enjoy and never call me a fool or a spado again. :)
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 06, 2014, 12:42:27 PM
Wine has some nice themes nowadays -- some looking better than the original window gadget  8) )

Hi Rob,

There's nothing like Windows Aero -- pretty, configurable, and solid as a rock. Linuxoid OpenGL-based aero is buggy, shaky, and crushy. Non-aero GTK-based drawable GUI's may sometimes look prettier than Windows at a first glance but are really nowhere as easy to skin with prebuilt images.

 :P
Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 12:52:58 PM
Outstanding !!!

Can I rerun the msvcbuild.bat again without any warnings with what you uploaded?


Quote
Enjoy and never call me a fool or a spado again.

I'm sure you have me confused with Aurel. I don't mess with those sitting on the throne.  8)

Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 01:02:26 PM
Mike,

I just gave the TS-64 version a try on Wine and it just returns to the command prompt. The version of king.scm worked with the crippled version I posted. Will try on Windows 7 64 bit.

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 06, 2014, 01:28:22 PM
I've just deleted the zip from my post. The exes are linked against MSVCR120.DLL instead of base MSVCRT.DLL. The exes won't run if it isn't installed on your system. I'm now trying to recompile and will be back shortly.
Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 01:33:01 PM
Thanks for the quick reply!
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 06, 2014, 01:53:35 PM
Here's the new zip. There's no way to link to MSVCRT.DLL in VS2013, so the exes are linked statically. This increases their size to 201KB but makes them completely independent.

Please re-download and let me know if they are working for you now. They do for me under 32-bit Vista, native 32-bit Win7, and WoW64 Win 7. The native 64-bit exe also works perfectly under 64-bit Win 7. Surprisingly, the 32-bit exe doesn't work under XP, apparently because VS2013 writes into the exe's PE header that this is a version 6 executable. Version 6 is Vista+ while XP's headers were marked as version 5. This needs further investigation. But by any means, both executables are OK for modern Windows platforms.

Quote
Can I rerun the msvcbuild.bat again without any warnings with what you uploaded?

Probably you shouldn't. I'd suggest using the original solutions instead. This bat file looks too simplistic for VS2013. :)

.
Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 02:40:11 PM
Nope. Wine run.


field 29  number of grains   268435456
field 30  number of grains   536870912
field 31  number of grains   1073741824
field 32  number of grains   -2147483648
field 33  number of grains   0
field 34  number of grains   0
field 35  number of grains   0
field 36  number of grains   0
field 37  number of grains   0
field 38  number of grains   0
field 39  number of grains   0
field 40  number of grains   0
field 41  number of grains   0
field 42  number of grains   0
field 43  number of grains   0
field 44  number of grains   0
field 45  number of grains   0
field 46  number of grains   0
field 47  number of grains   0
field 48  number of grains   0
field 49  number of grains   0
field 50  number of grains   0
field 51  number of grains   0
field 52  number of grains   0
field 53  number of grains   0
field 54  number of grains   0
field 55  number of grains   0
field 56  number of grains   0
field 57  number of grains   0
field 58  number of grains   0
field 59  number of grains   0
field 60  number of grains   0
field 61  number of grains   0
field 62  number of grains   0
field 63  number of grains   0
field 64  number of grains   0


:\TS-64\TS_VC_64\x64\Release>

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 06, 2014, 02:52:09 PM
IIRC Wine's settings allow you to select compatibility modes. Can you switch to Vista+ if there's such an option? (I repeat again, the 32-bit exe works perfectly in anything higher than XP and the 64-bit exe runs OK under native 64-bit Win 7 for me)
Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 03:02:03 PM
If you compiled with no changes to scheme.c, you will not have 64 bit range.

See my example changing long to long long and the fprint %ll change. I had a bunch of warnings saying that integers were truncated but it worked.

Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 03:07:48 PM
Rob,

newLisp looks interesting up to the point of being 32 bit across the board. They need to run on 64 bit before I will spend any time with it.

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 06, 2014, 03:17:06 PM
If you compiled with no changes to scheme.c, you will not have 64 bit range.

See my example changing long to long long and the fprint %ll change. I had a bunch of warnings saying that integers were truncated but it worked.

Ok,

So I'm a fool, a spado, and a liar.

Well well...

.
Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 04:24:59 PM
Mike,

The reason Rob added the .01 so 32 bit wouldn't overflow. Use this code in your tests.

Code: [Select]
(define (grains x)
   (let loop ((i 1) (j 1))
     (display " field ") (display i)
     (display "  number of grains   ")(display j)  (newline)
     (when (< i x) (loop (+ i 1) (* 2 j) )))) ; 'when' is an alias to 'if'
     
(define (main)
   (display "The reward of the King") (newline)
   (display "----------------------") (newline)
   (newline)
   (grains 64))
(main)
(newline)
(quit)

How it should look.


C:\TS-64>tinyscheme king.scm
The reward of the King
----------------------

 field 1  number of grains   1
 field 2  number of grains   2
 field 3  number of grains   4
 field 4  number of grains   8
 field 5  number of grains   16
 field 6  number of grains   32
 field 7  number of grains   64
 field 8  number of grains   128
 field 9  number of grains   256
 field 10  number of grains   512
 field 11  number of grains   1024
 field 12  number of grains   2048
 field 13  number of grains   4096
 field 14  number of grains   8192
 field 15  number of grains   16384
 field 16  number of grains   32768
 field 17  number of grains   65536
 field 18  number of grains   131072
 field 19  number of grains   262144
 field 20  number of grains   524288
 field 21  number of grains   1048576
 field 22  number of grains   2097152
 field 23  number of grains   4194304
 field 24  number of grains   8388608
 field 25  number of grains   16777216
 field 26  number of grains   33554432
 field 27  number of grains   67108864
 field 28  number of grains   134217728
 field 29  number of grains   268435456
 field 30  number of grains   536870912
 field 31  number of grains   1073741824
 field 32  number of grains   2147483648
 field 33  number of grains   4294967296
 field 34  number of grains   8589934592
 field 35  number of grains   17179869184
 field 36  number of grains   34359738368
 field 37  number of grains   68719476736
 field 38  number of grains   137438953472
 field 39  number of grains   274877906944
 field 40  number of grains   549755813888
 field 41  number of grains   1099511627776
 field 42  number of grains   2199023255552
 field 43  number of grains   4398046511104
 field 44  number of grains   8796093022208
 field 45  number of grains   17592186044416
 field 46  number of grains   35184372088832
 field 47  number of grains   70368744177664
 field 48  number of grains   140737488355328
 field 49  number of grains   281474976710656
 field 50  number of grains   562949953421312
 field 51  number of grains   1125899906842624
 field 52  number of grains   2251799813685248
 field 53  number of grains   4503599627370496
 field 54  number of grains   9007199254740992
 field 55  number of grains   18014398509481984
 field 56  number of grains   36028797018963968
 field 57  number of grains   72057594037927936
 field 58  number of grains   144115188075855872
 field 59  number of grains   288230376151711744
 field 60  number of grains   576460752303423488
 field 61  number of grains   1152921504606846976
 field 62  number of grains   2305843009213693952
 field 63  number of grains   4611686018427387904
 field 64  number of grains   -9223372036854775808

C:\TS-64>

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 06, 2014, 06:25:09 PM
Understood -- you want 64-bit integer math bitness. Then your last number isn't a mistake. That's a hex

F3 33 33 33   33 33 33 34

that causes a negative sign in a long long. To see it positive in TS, you'll have to have either unsigned long long or 128-bit integer calc altogether which aren't there by original design and platform implementation, respectively.

So all you wanna do is get rid of compiler warnings? Then 3 files have to be fixed -- scheme.c, scheme.h, and scheme-private.h. There are only a couple of printf() formats to fix but there are also a lot of function and variable redefinitions dependent on ivalue that now have to become long long int's (or rather __int64's, in VC parlance). Can do it for you tomorrow if you like.

.
Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 06:49:49 PM
That would be great Mike. I'm sure Rob will applicate the effort as well.
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 06, 2014, 08:55:22 PM
Rob doesn't use 64 bits, John.

Anyway, here's the 64-bit solution with the sources fixed. I don't guarantee 100% quality but all warnings have been cleared, not suppressed, but eliminated by redeclaration.  Please test.

.
Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 09:13:13 PM
Looks good Mike. Here is the results of the recompile using msvcbuild.bat.

Code: Text
  1. C:\TS64\TS_VC_64\src>msvcbuild.bat
  2.  
  3. C:\TS64\TS_VC_64\src>cl /nologo /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DWIN32 /DUSE_DL=1 /MT scheme.c dy
  4. nload.c
  5. scheme.c
  6. dynload.c
  7. Generating Code...
  8.  
  9. C:\TS64\TS_VC_64\src>link /nologo /out:tinyscheme.exe scheme.obj dynload.obj
  10.    Creating library tinyscheme.lib and object tinyscheme.exp
  11.  
  12. C:\TS64\TS_VC_64\src>tinyscheme.exe mk_init_scm.scm
  13.  
  14. C:\TS64\TS_VC_64\src>cl /nologo /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DWIN32 /DUSE_DL=1 /DUSE_EMB_INIT=1 /MT scheme.c dynload.c
  15. scheme.c
  16. dynload.c
  17. Generating Code...
  18.  
  19. C:\TS64\TS_VC_64\src>link /nologo /out:bin\tinyscheme.exe scheme.obj dynload.obj
  20.    Creating library bin\tinyscheme.lib and object bin\tinyscheme.exp
  21.  
  22. C:\TS64\TS_VC_64\src>cl /nologo /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DWIN32 /DUSE_DL=1 /DUSE_EMB_INIT=1 /MDd scheme.c dynload.c
  23. scheme.c
  24. dynload.c
  25. Generating Code...
  26.  
  27. C:\TS64\TS_VC_64\src>link /nologo /out:bin\tinyscheme_d.exe scheme.obj dynload.obj
  28.    Creating library bin\tinyscheme_d.lib and object bin\tinyscheme_d.exp
  29.  
  30. C:\TS64\TS_VC_64\src>del scheme.obj dynload.obj tinyscheme.* init_scm.h
  31.  
  32. C:\TS64\TS_VC_64\src>
  33.  

I think Rob is running Windows 7 64 bit. (not positive)  Prior examples he posted tend to make me think he is 64 bit aware. I don't think it is about not wanting to used a 64 bit version of TS but nothing was available on that platform. newLisp is 32 bit only. (Linux as well)

Thanks again for this effort. I would like to get the TSX (TinyScheme Extensions) working if all possible. Can you send me a guide of changes you made to TS so I fix TSX?

Title: Re: TinyScheme
Post by: JRS on September 06, 2014, 10:06:44 PM
I was able to compile newLisp for Linux 64 bit.

newLISP® v.10.6.0 Development Release Notes (http://www.newlisp.org/downloads/newLISP-10.6.0-Release.html)


jrs@laptop:~/NewLisp/newlisp-10.6.0$ ./newlisp
newLISP v.10.6.0 64-bit on Linux IPv4/6, options: newlisp -h

> (+ 2 2)
4
> (exit)
jrs@laptop:~/NewLisp/newlisp-10.6.0$ ./newlisp -h

newLISP v.10.6.0 Copyright (c) 2014 Lutz Mueller. All rights reserved.

usage: newlisp [file | url ...] [options ...] [file | url ...]

options:

 -h this help
 -n no init.lsp (must be first)
 -x <source> <target> link
 -v version
 -s <stacksize>
 -m <max-mem-MB> cell memory
 -e <quoted lisp expression>
 -l <path-file> log connections
 -L <path-file> log all
 -w <working dir>
 -c no prompts, net-eval, HTTP
 -C force prompts
 -t <usec-server-timeout>
 -p <port-no>
 -d <port-no> daemon mode
 -http only mode
 -6 IPv6 mode

more info at http://newlisp.org

jrs@laptop:~/NewLisp/newlisp-10.6.0$

Title: Re: TinyScheme
Post by: RobbeK on September 07, 2014, 01:31:27 AM
It is important to find your way through the labyrint of Lisp numbers --
Both Scheme R5RS ( and > ) and Common Lisp should be "full numeric tower" , however most of the Schemes are not (p.e; BigLoo, Chicken , Stalin aren't (and many more ).

so :   (let ( (a 1) (b 1.0))    ) means a is integer and b a floating point number

in CL the integer can be a bignumber ; to force it into a regular integer (for reason of speed ) , one can say in CL
(declare (type fixnum a)  (type real b) )  -- also forcing b into a real number and not a complex number.

both languages should have fractions  (/ 4)  means 1/4  , to convert it (in CL) use (float (/ 4)) -> 0.25  in Scheme one does
(exact->inexact (/ 4)) -> 0.25

Furthermore the "top" schemes have fx* , fx+, fx- etc...  iirc they are calle monodiadic ???  operators ? , they are restricted to two arguments ...   (once again to gain higher execution speed of the code)

NewLisp
----------
uses separate operators   + , - , * , / for integers and big numbers  and  add , sub , mul , div for floats or forcing into floats.
(be careful for (inc ) and (++ ) etc , too.
The bignumbers are invoked by adding an L at the tail   0L is a bignumber thus.

(+ 1 0L) makes 1L (look in the documentation for the correct operators   p.e.   (gcd  ) does not work on big numbers;

etc etc ...

best Rob   (some things may be very application specific )
-- running everything in 32 bit ----   (sadly)

John, glad to read you could compile it ,  imho NewLISP is au pair with languages as Perl and Python -- http://www.newlisp.org/CodePatterns.html   -- the FFI is superb , for string and integer arguments and results , you even do not have to declare those , it is possible to set up structures in Lisp, reading C structs .... etc ...

Hi, Mike ...  Aero ,  8)   ok -- unaware once again -- for myself the antique look of Japi is not important , probably for many others it is  ::)
Title: Re: TinyScheme
Post by: JRS on September 07, 2014, 07:11:02 AM
Quote
-- running everything in 32 bit ----   (sadly)

Are you saying you only have a 32 bit PC or are you saying you prefer 32 bit Lisp languages?

Quote
John, glad to read you could compile it ,  imho NewLISP is au pair with languages as Perl and Python --


I found a distribution of newLISP that had multiple makefile(s) for different platforms. Unfortunately there was only a 32 bit Windows solution.

I still need to get the TSX extension working on Win64 and fix SB. Taking on a newLISP isn't practical for me at the moment.  :-\
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 07, 2014, 09:03:44 AM
Hi John,

No, what I'm seeing in your BAT file report isn't good at all. That's why I said "use the solution; your bat file is too simplistic". If the cl that you're using is a VC12 from VS2013 then what it currently generates is a 32-bit debug-mode console application linked against the MSVCR120.DLL runtime, albeit with 64-bit integer calc. This DLL may or may not be installed on the user PC.

All your source files must be cl-ed with a /MT switch. This links them with a static runtime library as opposed to /MD which is the above DLL or /MDd which is its debug-mode counterpart.

Then if you're concerned about the size of the resultant exe then you should use the /O1 switch (optimize for size) rather than /O2 (optimize for speed) which would add extra 30KB or so.

Lastly, all your object files must be link-ed with a /MACHINE:X64 switch to generate a 64-bit executable. If omitted, a 32-bit binary is generated. I would also recommend adding an explicit /SUBSYSTEM:CONSOLE switch here to preclude any unwisely assumptions on behalf of the linker.

As for the other parts of the project, all their structures and functions that are communicating with TS directly or via memory calls should be aware that TS' ivalue and len parameters and their  dependencies are now defined as __int64 rather than int or long, and all rvalue and its dependencies are defined as long double rather than double. The latter doesn't make much difference for Windows where both doubles and long doubles are 8-byte quantities, but it may make a difference in Linux where long doubles are 12 bytes in size IIRC.

So look through my fixes searching for __int64 and long double and make sure all functions and structures in the other parts of the projects are redefined accordingly. This may require a lot of trial and error in real time.

Title: Re: TinyScheme
Post by: JRS on September 07, 2014, 09:23:52 AM
Mike,

I'm using VS 2013 and selected the 64 bit VC12 console compiler from the tools short cuts. What do you mean by use the solution? The solution provided by the project is the msvcbuild.bat which assumes you selected the correct CL for the job.

I will do a DIFF of your changes to scheme.c and the supporting files and carry them forward with the TSX module that has its own msvcbuild.bat.

John
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 07, 2014, 09:36:19 AM
A solution is the MS Visual Studio's .sln file which unites one or more interdependent VC projects into a common workspace. Double clicking on it under Windows will spawn your VS2013 with the TS sources opened and project settings adjusted exactly as I set them. You can inspect them in the Project->Properties... dialog (see C/C++->Command Line and Linker->Comand Line sections) and you can also rebuild the project or the entire solution via the respective Build->Rebuild menu items.

This is how enlightened programmers usually work under Windows these days. Leave comman-line .bat and makefiles to stray Linux visitors.

:)
Title: Re: TinyScheme
Post by: JRS on September 07, 2014, 09:50:05 AM
Unfortunately SB is a command line build system that supports multiple platforms. I'm willing to use more modern tools on Windows for extension libraries but that's it. SB is built from scratch from C files. (headers, syntax tables, docs, ...) Peter Verhas did an amazing job 12 years ago with his build system.

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 07, 2014, 10:01:52 AM
But you don't need either SB or Peter Verhas to build Tiny Scheme. 12 years is a lot of time in IT. I think the first LISPs were either machine coded or card punched by hand but it doesn't mean we're suppused to "maintain the tradition" building TS in the year of 2014.

As a matter of fact, your SB sources for Windows can also be formulated as a Code::Blocks MinGW  workspace or VS2013 solution to make editing and compilation more up to date and dev friendly. You're so concerned about BASIC's future and you're clutching so tightly onto the past with its development tools.
Title: Re: TinyScheme
Post by: JRS on September 07, 2014, 10:15:15 AM
If you download Dave COM project, (IDE/Debugger) he uses the method you just mentioned to build SB within VS. He even did a YouTube video on how to set it up. As you know, Windows is a secondary platform for me and if it wasn't for you and Charles's help, I wouldn't be spending the time I have on this. Linux is just easier to use (for me) and ahead of the game in many areas. (IMHO) Being open source is icing.
Title: Re: TinyScheme
Post by: JRS on September 07, 2014, 05:36:49 PM
Mike,

Just wanted to say what a great job you did on the TinyScheme Windows 32 bit to 64 bit conversion. This will help a lot with the TSX extension conversion.


long = __int64
int = __int64
double = long double


The following lines needed special attention and if you have time to explain these changes, it would also help in the understanding of this migration.


728 sc->fcells -= (long)n;
1888 p[0]=(char)c;
2043 *plen=(int)strlen(p);
3746 - 3754
          s_retbool(Cisalpha((int)ivalue(car(sc->args))));
     case OP_CHARNP:     /* char-numeric? */
       s_retbool(Cisdigit((int)ivalue(car(sc->args))));
     case OP_CHARWP:     /* char-whitespace? */
       s_retbool(Cisspace((int)ivalue(car(sc->args))));
     case OP_CHARUP:     /* char-upper-case? */
       s_retbool(Cisupper((int)ivalue(car(sc->args))));
     case OP_CHARLP:     /* char-lower-case? */
       s_retbool(Cislower((int)ivalue(car(sc->args))));
4018 size=(off_t)(p->rep.string.curr-p->rep.string.start+1);
5143 retcode=(int)sc.retcode;

Title: Re: TinyScheme
Post by: JRS on September 07, 2014, 10:45:45 PM
Mike,

I'm working on the TSX extension module and have the following warnings. I did the int and long conversion but these warnings remain.  :(


C:\TS\tinyscheme-master\tsx>cl /nologo /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /DWIN32 /DUSE_DL=1 /I..\src /MT tsx.c
tsx.c
tsx.c(328) : warning C4244: '=' : conversion from '__time64_t' to 'long', possible loss of data
tsx.c(410) : warning C4133: 'function' : incompatible types - from '__int64 *' to 'LPINT'
tsx.c(511) : warning C4267: 'function' : conversion from 'size_t' to 'int', possible loss of data
tsx.c(567) : warning C4244: 'function' : conversion from '__int64' to 'int', possible loss of data
tsx.c(625) : warning C4267: 'function' : conversion from 'size_t' to 'int', possible loss of data
tsx.c(682) : warning C4244: 'function' : conversion from '__int64' to 'int', possible loss of data

C:\TS\tinyscheme-master\tsx>link /nologo /DLL /out:dll\tsx.dll /export:init_tsx tsx.obj ws2_32.lib
   Creating library dll\tsx.lib and object dll\tsx.exp

C:\TS\tinyscheme-master\tsx>cl /nologo /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /DWIN32 /DUSE_DL=1 /I..\src /MDd tsx.c
tsx.c
tsx.c(328) : warning C4244: '=' : conversion from '__time64_t' to 'long', possible loss of data
tsx.c(410) : warning C4133: 'function' : incompatible types - from '__int64 *' to 'LPINT'
tsx.c(511) : warning C4267: 'function' : conversion from 'size_t' to 'int', possible loss of data
tsx.c(567) : warning C4244: 'function' : conversion from '__int64' to 'int', possible loss of data
tsx.c(625) : warning C4267: 'function' : conversion from 'size_t' to 'int', possible loss of data
tsx.c(682) : warning C4244: 'function' : conversion from '__int64' to 'int', possible loss of data

C:\TS\tinyscheme-master\tsx>link /nologo /DLL /out:dll\tsx_d.dll /export:init_tsx tsx.obj ws2_32.lib
   Creating library dll\tsx_d.lib and object dll\tsx_d.exp

C:\TS\tinyscheme-master\tsx>del tsx.obj

C:\TS\tinyscheme-master\tsx>
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 07, 2014, 11:42:45 PM
John,

First and foremost, be prepared that conversion will be a multi-stage process. You won't be able to get rid of all warnings at once. As you fix the current list, new ones will spring up at various places because the declarations you've just fixed are referenced there. As you fix up those, they will cause yet more new warnings at different places and so on and so forth until the entire tree of cross references have gotten eventually fixed up.

This is a tiresome process and it is best dealt with in the Visual Studio IDE where you can click the compilation warnings list and use the RMB popup menu to jump to the corresponding structure and function declarations and definitions. Recompile after each session and be especially sure to clean the solution with the appropriate build menu item before each rebuild. Otherwise you may get your changes linked against the old object files that are still expecting int's and long's.

I can't offer more help right now after a night of heavy coding but I'll try and look into your questions more closely after some 7 or 8 hours of sleep.

Good night.
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 08, 2014, 07:21:20 AM
Hi John,

Here are my explanations:


728 sc->fcells -= (long)n; // The number of memory cells (i.e. chunks) where TS stores its internal data
                                         // isn't platform-dependent. If the authors determined it to be, say, 5000 then
                                         // a long-wide field is sufficient to store it on 64 bits too.

1888 p[0]=(char)c;          // p[] is a char array on any platform even if c is fetched
                                         // into the function in an __int64-wide argument.

2043 *plen=(int)strlen(p); // That was an unwize decision. It should be a platform-dependent (size_t)
                                           // cast because 64-bit strings may be huge. Try changing the *plen argument
                                           // to __int64* plen or size_t* plen and fix up any extra compiler warnings
                                           // that may appear due to the change.

3746 - 3754                     // These are functions that return simple YES or NO (i.e. TRUE or FALSE) so there's
                                           // no need to make them any wider.
          s_retbool(Cisalpha((int)ivalue(car(sc->args))));
     case OP_CHARNP:     /* char-numeric? */
       s_retbool(Cisdigit((int)ivalue(car(sc->args))));
     case OP_CHARWP:     /* char-whitespace? */
       s_retbool(Cisspace((int)ivalue(car(sc->args))));
     case OP_CHARUP:     /* char-upper-case? */
       s_retbool(Cisupper((int)ivalue(car(sc->args))));
     case OP_CHARLP:     /* char-lower-case? */
       s_retbool(Cislower((int)ivalue(car(sc->args))));

4018 size=(off_t)(p->rep.string.curr-p->rep.string.start+1); // size is defined as off_t
                                                             // (i.e. offset_type) which is a platform-dependent
                                                             // quantity adjusted by the compiler to 64 bits
                                                             // automatically.

5143 retcode=(int)sc.retcode;// Retcodes are usually program-defined small values to signal TRUE or FALSE,
                                          // success or failure, etc. I don't think they will change all by themselves due to
                                          // migration to 64 bits.
Title: Re: TinyScheme
Post by: JRS on September 08, 2014, 07:24:17 AM
Thanks Mike for the explanation of the changes. Very helpful. Do have a moment to wrap up the warnings in the TSX extension module for TinyScheme 64?

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 08, 2014, 07:30:56 AM
First and foremost, be prepared that conversion will be a multi-stage process.

A moment, you say? ;)
Title: Re: TinyScheme
Post by: JRS on September 08, 2014, 07:52:00 AM
Quote
A moment, you say?

I was in deep thought about what I'm going to have to do to fix SB Win 64 when I wrote that. Sorry.

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 08, 2014, 08:35:47 AM
I was in deep thought about what I'm going to have to do to fix SB Win 64...

Strictly speaking, I don't think you should make any fixes to your existing 64-bit SB under either Windows or Linux. If it compiles with GCC without complaints on both platforms just leave it as it is. If all its sizable types are properly defined with size_t, char_t, wchar_t, etc. automatic qualifiers then the compiler will do the job for you transparently. The only thing you will have to do manually is change your maths to 64 bits using long long versions of arguments and respective math functions like sinl(), fmodl(), etc. and string-to-number conversion functions like strtold(), etc.

Or you may leave the args and functions alone, in which case you will simply have the same old 32-bit maths and strings but on a 64-bit platform. The final decision is yours depending on expediency and your own willingness and perseverance.
Title: Re: TinyScheme
Post by: JRS on September 08, 2014, 09:48:18 AM
Thanks Mike for having a peek under the covers at SB. Under Linux going to 64 bit was just a compiler switch. gcc sees long as a 64 bit long if that is the platform your compiling under. I want to keep the single source tree tradition with SB if all possible. The only issue I'm seeing in SB Win 64 is the 32 bit PRINT issue. (kings reward) SB doesn't complain with assignments of big numbers, only PRINTing them.

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 08, 2014, 12:59:32 PM
My 3G modem suddenly went down and I had to go out to buy me a new one. This one is slower than my former one but it's too late here to buy a better one. Guess I'll have to go out one more time tomorrow morning...

So why then don't you try and compile the original TS sources with MinGW GCC on 64 bits to see how its maths and print behave without modification?
Title: Re: TinyScheme
Post by: JRS on September 08, 2014, 01:05:01 PM
Quote
So why then don't you try and compile the original TS sources with MinGW GCC on 64 bits to see how its maths and print behave without modification?

That was my first try at going 64 bit with TinyScheme. Too many errors to proceed. When I found the VS version, that renewed my hope.

SB reacts the same way as TS did using TDM-GCC-64 but compiles fine without error.
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 08, 2014, 01:15:22 PM
So let me ask once again: does TDM-GCC refuse to compile under 64-bit Windows the original unmodified TS sources as a full-blown 64-bit application with correct 64-bit maths and print, without warnings? I don't have 64-bit GCC 4.8.1 installed under my Win 7 yet though I do have it in a zip for quite some time since I downoaded it last winter. :)
Title: Re: TinyScheme
Post by: JRS on September 08, 2014, 02:12:54 PM
I had to remove under the Linux section of the makefile the -ldl library as there isn't a TDM-GCC equivalent. It compiled but not generating 64 bit numbers.


C:\tinyscheme-master\src>mingw32-make -B
gcc -fpic -pedantic -I. -c -g -Wno-char-subscripts -O -DUSE_STRLWR=0 -DUSE_DL=1 -DUSE_MATH=1 -DUSE_ASCII_NAMES=0  scheme.c
scheme.c: In function 'alloc_cellseg':
scheme.c:584:14: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
          if(((unsigned long)cp)%adj!=0) {
              ^
scheme.c:585:28: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
            cp=(char*)(adj*((unsigned long)cp/adj+1));
                            ^
scheme.c:585:15: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
            cp=(char*)(adj*((unsigned long)cp/adj+1));
               ^
gcc -fpic -pedantic -I. -c -g -Wno-char-subscripts -O -DUSE_STRLWR=0 -DUSE_DL=1 -DUSE_MATH=1 -DUSE_ASCII_NAMES=0  dynload.c
dynload.c: In function 'scm_load_ext':
dynload.c:108:33: warning: ISO C forbids assignment between function pointer and 'void *' [-Wpedantic]
          *(void **)&module_init = dl_proc(dll_handle, init_fn);
                                 ^
gcc -shared -o libtinyscheme.dll scheme.o dynload.o -lm
ar crs libtinyscheme.a scheme.o dynload.o
gcc -fpic -pedantic -o scheme -g -Wno-char-subscripts -O scheme.o dynload.o -lm

C:\tinyscheme-master\src>dir
 Volume in drive C has no label.
 Volume Serial Number is 0C51-A073

 Directory of C:\tinyscheme-master\src

09/08/2014  03:06 PM    <DIR>          .
09/08/2014  03:06 PM    <DIR>          ..
03/29/2014  08:33 AM             4,062 BUILDING
03/29/2014  08:33 AM            14,636 CHANGES
03/29/2014  08:33 AM             1,548 COPYING
03/29/2014  08:33 AM             3,324 dynload.c
03/29/2014  08:33 AM               281 dynload.h
09/08/2014  03:06 PM            11,003 dynload.o
03/29/2014  08:33 AM            10,490 hack.txt
03/29/2014  08:33 AM            24,511 init.scm
09/08/2014  03:06 PM           258,116 libtinyscheme.a
09/08/2014  03:06 PM           386,666 libtinyscheme.dll
09/08/2014  03:05 PM             1,995 makefile
03/29/2014  08:33 AM            17,238 Manual.txt
03/29/2014  08:33 AM             3,714 MiniSCHEMETribute.txt
03/29/2014  08:33 AM               797 mk_init_scm.scm
03/29/2014  08:33 AM               976 msvcbuild.bat
03/29/2014  08:33 AM            22,867 opdefines.h
03/29/2014  08:33 AM             5,103 scheme-private.h
03/29/2014  08:33 AM           149,655 scheme.c
09/08/2014  03:06 PM           397,031 scheme.exe
03/29/2014  08:33 AM             7,327 scheme.h
09/08/2014  03:06 PM           245,757 scheme.o
              21 File(s)      1,567,097 bytes
               2 Dir(s)  123,526,754,304 bytes free

C:\tinyscheme-master\src>scheme
TinyScheme 1.41
ts> (load "king.scm")
Loading king.scm
The reward of the King
----------------------

 field 1  number of grains   1
 field 2  number of grains   2
 field 3  number of grains   4
 field 4  number of grains   8
 field 5  number of grains   16
 field 6  number of grains   32
 field 7  number of grains   64
 field 8  number of grains   128
 field 9  number of grains   256
 field 10  number of grains   512
 field 11  number of grains   1024
 field 12  number of grains   2048
 field 13  number of grains   4096
 field 14  number of grains   8192
 field 15  number of grains   16384
 field 16  number of grains   32768
 field 17  number of grains   65536
 field 18  number of grains   131072
 field 19  number of grains   262144
 field 20  number of grains   524288
 field 21  number of grains   1048576
 field 22  number of grains   2097152
 field 23  number of grains   4194304
 field 24  number of grains   8388608
 field 25  number of grains   16777216
 field 26  number of grains   33554432
 field 27  number of grains   67108864
 field 28  number of grains   134217728
 field 29  number of grains   268435456
 field 30  number of grains   536870912
 field 31  number of grains   1073741824
 field 32  number of grains   -2147483648
 field 33  number of grains   0
 field 34  number of grains   0
 field 35  number of grains   0
 field 36  number of grains   0
 field 37  number of grains   0
 field 38  number of grains   0
 field 39  number of grains   0
 field 40  number of grains   0
 field 41  number of grains   0
 field 42  number of grains   0
 field 43  number of grains   0
 field 44  number of grains   0
 field 45  number of grains   0
 field 46  number of grains   0
 field 47  number of grains   0
 field 48  number of grains   0
 field 49  number of grains   0
 field 50  number of grains   0
 field 51  number of grains   0
 field 52  number of grains   0
 field 53  number of grains   0
 field 54  number of grains   0
 field 55  number of grains   0
 field 56  number of grains   0
 field 57  number of grains   0
 field 58  number of grains   0
 field 59  number of grains   0
 field 60  number of grains   0
 field 61  number of grains   0
 field 62  number of grains   0
 field 63  number of grains   0
 field 64  number of grains   0

C:\tinyscheme-master\src>
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 08, 2014, 03:06:04 PM
And does the resultant TS give a correct answer to such a command:

(- 80000000001 80000000000)

which should be 1? If it doesn't then TDM GCC can't automatically convert TS' original code to legit 64 bits. But then you can also try and use TDM GCC instead of VC to compile my fixes to see if the resultant binary is smaller, or faster, or whatever...
Title: Re: TinyScheme
Post by: JRS on September 08, 2014, 03:09:36 PM


C:\tinyscheme-master\src>scheme
TinyScheme 1.41
ts> (- 80000000001 80000000000)
1
ts>


It works!
Title: Re: TinyScheme
Post by: JRS on September 08, 2014, 03:25:19 PM
Mike,

If we can get by these three warnings, I wonder if it would work. (kings reward - ext. int) I also changed the %l to %ll which didn't cause any errors or warnings but didn't solve the zero problem in KR fields beyond 32.  :-[

If we can get TDM-GCC=64 to compile TS with little change, I'm going gcc across the board. I'll only use VS2013 for Dave's COM stuff.


C:\tinyscheme-master\src>mingw32-make -B
gcc -fpic -I. -c -g -Wno-char-subscripts -O -DUSE_STRLWR=0 -DUSE_DL=1 -DUSE_MATH=1 -DUSE_ASCII_NAMES=0  scheme.c
scheme.c: In function 'alloc_cellseg':
scheme.c:584:14: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
          if(((unsigned long)cp)%adj!=0) {
              ^
scheme.c:585:28: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
            cp=(char*)(adj*((unsigned long)cp/adj+1));
                            ^
scheme.c:585:15: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
            cp=(char*)(adj*((unsigned long)cp/adj+1));
               ^
gcc -fpic -I. -c -g -Wno-char-subscripts -O -DUSE_STRLWR=0 -DUSE_DL=1 -DUSE_MATH=1 -DUSE_ASCII_NAMES=0  dynload.c
gcc -shared -o libtinyscheme.dll scheme.o dynload.o -m64 -lm
ar crs libtinyscheme.a scheme.o dynload.o
gcc -fpic -o scheme -g -Wno-char-subscripts -O scheme.o dynload.o -m64 -lm

C:\tinyscheme-master\src>

Title: Re: TinyScheme
Post by: JRS on September 08, 2014, 04:37:55 PM
I was able to eliminate the warnings with the following code change.

Code: Scheme
  1.          // if(((unsigned long)cp)%adj!=0) {
  2.          if(((intptr_t)cp)%adj!=0) {
  3.            // cp=(char*)(adj*((unsigned long)cp/adj+1));
  4.            cp=(char*)(adj*((intptr_t)cp/adj+1));
  5.  


C:\tinyscheme-master\src>mingw32-make -B
gcc -fpic -I. -c -g -Wno-char-subscripts -O -DUSE_STRLWR=0 -DUSE_DL=1 -DUSE_MATH=1 -DUSE_ASCII_NAMES=0  scheme.c
gcc -fpic -I. -c -g -Wno-char-subscripts -O -DUSE_STRLWR=0 -DUSE_DL=1 -DUSE_MATH=1 -DUSE_ASCII_NAMES=0  dynload.c
gcc -shared -m64 -o libtinyscheme.dll scheme.o dynload.o -lm
ar crs libtinyscheme.a scheme.o dynload.o
gcc -fpic -o scheme -g -Wno-char-subscripts -O scheme.o dynload.o -lm

C:\tinyscheme-master\src>scheme king.scm
The reward of the King
----------------------

 field 1  number of grains   1
 field 2  number of grains   2
 field 3  number of grains   4
 field 4  number of grains   8
 field 5  number of grains   16
 field 6  number of grains   32
 field 7  number of grains   64
 field 8  number of grains   128
 field 9  number of grains   256
 field 10  number of grains   512
 field 11  number of grains   1024
 field 12  number of grains   2048
 field 13  number of grains   4096
 field 14  number of grains   8192
 field 15  number of grains   16384
 field 16  number of grains   32768
 field 17  number of grains   65536
 field 18  number of grains   131072
 field 19  number of grains   262144
 field 20  number of grains   524288
 field 21  number of grains   1048576
 field 22  number of grains   2097152
 field 23  number of grains   4194304
 field 24  number of grains   8388608
 field 25  number of grains   16777216
 field 26  number of grains   33554432
 field 27  number of grains   67108864
 field 28  number of grains   134217728
 field 29  number of grains   268435456
 field 30  number of grains   536870912
 field 31  number of grains   1073741824
 field 32  number of grains   2147483648
 field 33  number of grains   0
 field 34  number of grains   0
 field 35  number of grains   0
 field 36  number of grains   0
 field 37  number of grains   0
 field 38  number of grains   0
 field 39  number of grains   0
 field 40  number of grains   0
 field 41  number of grains   0
 field 42  number of grains   0
 field 43  number of grains   0
 field 44  number of grains   0
 field 45  number of grains   0
 field 46  number of grains   0
 field 47  number of grains   0
 field 48  number of grains   0
 field 49  number of grains   0
 field 50  number of grains   0
 field 51  number of grains   0
 field 52  number of grains   0
 field 53  number of grains   0
 field 54  number of grains   0
 field 55  number of grains   0
 field 56  number of grains   0
 field 57  number of grains   0
 field 58  number of grains   0
 field 59  number of grains   0
 field 60  number of grains   0
 field 61  number of grains   0
 field 62  number of grains   0
 field 63  number of grains   0
 field 64  number of grains   0

C:\tinyscheme-master\src>

Title: Re: TinyScheme
Post by: JRS on September 08, 2014, 05:31:03 PM
I feel the only outstanding issue with using MinGW-TDM-64 is getting printf() correctly printing 64 bit values with a %l format option.

Any ideas?

I'm beginning to think this isn't a printf issue.
Title: TinyScheme - The End ?
Post by: JRS on September 08, 2014, 07:55:55 PM
I noticed that we have lost Charles along the way taking over his forum with our Lisp projects. He hasn't posted an update since Aug. 24th which seems unusual to me. Should we take this somewhere else? I would be willing to open up the All BASIC forum with a fresh start and open to All BASIC programmers. Since BP.org is gone, maybe it would make sense.

@Mike - Would you be interested in helping me setup a new All BASIC forum and be a co-admin / moderator?

With Charles's permission, I could move the Lisp (XBLisp, TS, ...) intact to the All BASIC forum to give it a head start. We could also rummage through the old All BASIC forum for content that might be worth moving to the new forum. All of this depends on you and Charles's feelings about this continuing here.
 

If we don't pull together as a community, this is our fate.

(http://files.allbasic.info/AllBasic/rip-basic.png)
Title: Re: TinyScheme
Post by: Charles Pegge on September 08, 2014, 11:29:03 PM

Hi John,

I have been quietly following the LISP threads. You are welcome to continue them here if that suits you. It is good to see how things are progressing.
Title: Re: TinyScheme
Post by: JRS on September 08, 2014, 11:33:39 PM
Just wanted to make sure you are still good with the Open Forum abuse.

I'm happy folks (Mike) are taking an interest in 64 bit Windows.

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 09, 2014, 02:39:30 AM
I feel the only outstanding issue with using MinGW-TDM-64 is getting printf() correctly printing 64 bit values with a %l format option.

Hi John,

Please goto line 1937 in scheme.c and overwrite what's in there with the following code (I told you Windows printf() and its family in msvcrt.dll do not understand %ll prefixes in their format strings, and TDM GCC will not convert them for you automatically because they are hardcoded string literals):

Code: [Select]
     } else if (is_number(l)) {
          p = sc->strbuff;
          if (f <= 1 || f == 10) /* f is the base for numbers if > 1 */ {
if (num_is_integer(l)) {
snprintf(p, STRBUFFSIZE, "%I64d", ivalue_unchecked(l));
}
else {
snprintf(p, STRBUFFSIZE, "%.20g", rvalue_unchecked(l));
  /* r5rs says there must be a '.' (unless 'e'?) */
                   f = (int)strcspn(p, ".e");
                   if (p[f] == 0) {
                        p[f] = '.'; /* not found, so add '.0' at the end */
                        p[f+1] = '0';
                        p[f+2] = 0;
                   }
              }
          } else {
__int64 v = ivalue(l);
if (f == 16) {
if (v >= 0)
snprintf(p, STRBUFFSIZE, "%I64x", v);
else
snprintf(p, STRBUFFSIZE, "-%I64x", -v);
}
else if (f == 8) {
if (v >= 0)
snprintf(p, STRBUFFSIZE, "%I64o", v);
else
snprintf(p, STRBUFFSIZE, "-%I64o", -v);
}
else if (f == 2) {
unsigned __int64 b = (v < 0) ? -v : v;
p = &p[STRBUFFSIZE - 1];
*p = 0;
do { *--p = (b & 1) ? '1' : '0'; b >>= 1; } while (b != 0);
if (v < 0) *--p = '-';
}
  }


Also goto line 1157 there and overwrite it with the following:

Code: [Select]
     else if (*name == 'o') {/* #o (octal) */
          snprintf(tmp, STRBUFFSIZE, "0%s", name+1);
  sscanf(tmp, "%I64o", (__int64 unsigned *)&x);
          return (mk_integer(sc, x));
     } else if (*name == 'd') {    /* #d (decimal) */
sscanf(name + 1, "%I64d", (__int64 *)&x);
          return (mk_integer(sc, x));
     } else if (*name == 'x') {    /* #x (hex) */
          snprintf(tmp, STRBUFFSIZE, "0x%s", name+1);
  sscanf(tmp, "%I64x", (__int64 unsigned *)&x);
          return (mk_integer(sc, x));


I think this will fix your console output for long numbers.
Title: Re: TinyScheme - The End ?
Post by: Mike Lobanovsky on September 09, 2014, 02:54:15 AM
@Mike - Would you be interested in helping me setup a new All BASIC forum and be a co-admin / moderator?

John,

I don't think it would be a wise decision to split our meager human resources any further. The OxygenBasic forum is a well-established resource with good general visitor rate and a solid base of registered fellow BASIC developers.

We're acting on its Open Forum board and we aren't spawning multiple threads here. We've got only two of them -- TS and Lisp-in-Basic -- and I don't think we'll need any more. The former was an offspring of the latter but noone can foretell that we won't ever come back to the original topic. It isn't just ripe at the moment but who knows...
Title: Re: TinyScheme
Post by: JRS on September 09, 2014, 07:21:20 AM
Thanks Mike for the code and effort to resolve the 64 bit C printing issue. It would save me some time if you were to post your working code. Is there any additional includes needed or type casting to eliminate warnings?

I have been chatting with Dave via e-mail and it looks like the COM / VB effort is now in my hands. Dave has some debilitating issues with his arms that makes extended programming sessions very painful (physical) for him. It would be great if Charles can have a look at Dave's code and see if it can be combined with the DLLC effort and O2 COM. I have shifted my efforts from TinyScheme (once SB TS Win64 ext. mod. is working) to understanding better where Dave has left off. I think most of his goals have been completed.

OT

I seem to be making some progress on the Twitter front and picking up a few high asset likes.

(http://files.allbasic.info/Twitter/osn_fav.png)
(http://files.allbasic.info/Twitter/ln_fav.png)
(http://files.allbasic.info/Twitter/gwn_fav.png)

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 09, 2014, 08:39:00 AM
It would save me some time if you were to post your working code. Is there any additional includes needed or type casting to eliminate warnings?

I don't clearly see what working code you're expecting from me. I have none except the one I fixed for VS2013 and uploaded here.

I repeat I do not have a 64-bit TDM GCC installed to run the compilations myself. As I understood from you previous messages, you secceeded in compiling the original TS code into a genuine 64-bit executable without warnings using your installation of 64-bit TDM GCC for Windows, and the only issue you're having now is printing your math with correct bitness.

So why don't you do as I suggest in my earlier message: overwrite (or rem out temporarily) the old code with what I offered and recompile. I think it will make your print work as expected. As simple as that - no warnings and working print in a 64-bit TS when compiled with TDM GCC. Just forget VC and my submission if TDM GCC is so smart as to turn the sources to 64 bits automatically except the format strings that I fixed for you manually. If this works as expected then you can add conditional compilation to these two print portions with #ifdef WIN32 and keep the original %l's for Linux. This will conform to your principle of one source for all platforms and bitnesses.
Title: Re: TinyScheme
Post by: JRS on September 09, 2014, 09:07:34 AM
Got it. Great advice which I will follow. I'll use my last  warningless/errorless TDM-GCC-64 code as a base.  At this point my plan is to use gcc 4.8.1 across the board for SB. (all supported OSs) As mentioned before, I'm only using VS2008 at the moment with Dave's COM stuff. I tried to upgrade his code to VS2013 and it broke too many things due to deprecation. (most were warnings with only one hard error) If there is any interest in Dave's effort, the Github repository is the place to go. Dave has a Windows installer for the SB IDE/Debugger in the distribution if you want to give it a try. I works fine on both XP & Win7 64. (WOW)

Title: Re: TinyScheme
Post by: RobbeK on September 09, 2014, 02:16:54 PM
Something not mentioned about Lisp  yet ,  maybe one of its most powerful tools -- the macro (in the sense of "a programmable programming language - extending the language ).

Maybe you're already bored by declaring and initiating all those globals

(define something somewhat) ....   (define something-else somewhat-else) etc ...    this is a solution (did this in NewLisp )

(define define-Integer   ;; can be changed to any type and even typeless
  (lambda-macro ()
     (doargs (i) (set i 0))))

now we can do   (define-Integer a z e r t y)      resulting a..y is defined as 0 (an integer)

Similar mechanisms exist in Scheme and Common Lisp (but here it is easier, because NewLisp does not need to compile such things )
The (set i . ) does the trick here , it doesn't quote i , but points to the value pointed by i .. 

I've been told, writing macro's in C really is not easy .. (?)

best Rob

 



.
Title: Re: TinyScheme
Post by: JRS on September 09, 2014, 02:40:36 PM
Thankfully BASIC was spared. I can only imagine what picture would be used.   :o

Is it just me or does Lisp seem more popular and feature rich on the Linux side? I have 64 bit versions of all the most popular Lisp languages built from scratch on my box. Porting these to Windows isn't walk in the park.



Title: Re: TinyScheme
Post by: RobbeK on September 09, 2014, 02:43:48 PM
Hi John ...   TinyScheme has the full power of writing any macro-expansion whatsoever !! 8)
Title: Re: TinyScheme
Post by: JRS on September 09, 2014, 02:51:28 PM
I'm still waiting for you to fall in love with SB / TS / SDL_gfx. I would be willing to add SDL_gfx to TS if you were to show some interest in this direction. Time is running out and I'm getting close to wrapping up the SB/TS project. I need to move on to COM/VB and getting the SB 2.2 release finalized.

Title: Re: TinyScheme
Post by: JRS on September 09, 2014, 07:56:06 PM
Quote from: Mike
I think this will fix your console output for long numbers.

I made your changes on a fresh copy of the source and we are still getting zeros from fields 33 to 64.

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 09, 2014, 08:44:44 PM
I made your changes on a fresh copy of the source and we are still getting zeros from fields 33 to 64.

Would you be so kind as to do me a favour by spending three minutes of your precious time on the following:


1. Take the three source files of Tiny Scheme that I've recently fixed for use under 64 bits and uploaded here.

2. Overwrite what's there in my fixed scheme.c with my latest fixes taken from this message (http://www.oxygenbasic.org/forum/index.php?topic=1185.msg11253#msg11253) of mine.

3. Compile the three files with your TDM GCC under your 64-bit Windows 7.


I'm dying to be shown what the resultant exe will print in response to King's Reward.

Thanks!
Title: Re: TinyScheme
Post by: JRS on September 09, 2014, 08:54:30 PM

C:\tinyscheme-master\src>mingw32-make -B
gcc -fpic -pedantic -I. -c -g -Wno-char-subscripts -O -DUSE_STRLWR=0 -DUSE_DL=1 -DUSE_MATH=1 -DUSE_ASCII_NAMES=0  scheme.c
scheme.c: In function 'alloc_cellseg':
scheme.c:584:14: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
          if(((unsigned long)cp)%adj!=0) {
              ^
scheme.c:585:28: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
            cp=(char*)(adj*((unsigned long)cp/adj+1));
                            ^
scheme.c:585:15: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
            cp=(char*)(adj*((unsigned long)cp/adj+1));
               ^
scheme.c: In function 'mk_atom':
scheme.c:1143:41: warning: C++ style comments are not allowed in ISO C90 [enabled by default]
    return mk_real(sc, strtold(q, NULL));//    atof(q));
                                         ^
scheme.c:1143:41: warning: (this will be reported only once per input file) [enabled by default]
scheme.c: In function 'opexe_2':
scheme.c:3176:11: warning: passing argument 2 of 'modf' from incompatible pointer type [enabled by default]
           } else if(modf(rvalue_unchecked(x),&dd)==0.0) {
           ^
In file included from scheme.c:29:0:
c:\tdm-gcc-64\x86_64-w64-mingw32\include\math.h:196:18: note: expected 'double *' but argument is of type 'long double *'
   double __cdecl modf(double _X,double *_Y);
                  ^
gcc -fpic -pedantic -I. -c -g -Wno-char-subscripts -O -DUSE_STRLWR=0 -DUSE_DL=1 -DUSE_MATH=1 -DUSE_ASCII_NAMES=0  dynload.c
dynload.c: In function 'scm_load_ext':
dynload.c:108:33: warning: ISO C forbids assignment between function pointer and 'void *' [-Wpedantic]
          *(void **)&module_init = dl_proc(dll_handle, init_fn);
                                 ^
gcc -shared -o libtinyscheme.dll scheme.o dynload.o -lm
ar crs libtinyscheme.a scheme.o dynload.o
gcc -fpic -pedantic -o scheme -g -Wno-char-subscripts -O scheme.o dynload.o -lm

C:\tinyscheme-master\src>dir


Output


C:\tinyscheme-master\src>scheme king.scm
The reward of the King
----------------------

 field 1  number of grains   1
 field 2  number of grains   2
 field 3  number of grains   4
 field 4  number of grains   8
 field 5  number of grains   16
 field 6  number of grains   32
 field 7  number of grains   64
 field 8  number of grains   128
 field 9  number of grains   256
 field 10  number of grains   512
 field 11  number of grains   1024
 field 12  number of grains   2048
 field 13  number of grains   4096
 field 14  number of grains   8192
 field 15  number of grains   16384
 field 16  number of grains   32768
 field 17  number of grains   65536
 field 18  number of grains   131072
 field 19  number of grains   262144
 field 20  number of grains   524288
 field 21  number of grains   1048576
 field 22  number of grains   2097152
 field 23  number of grains   4194304
 field 24  number of grains   8388608
 field 25  number of grains   16777216
 field 26  number of grains   33554432
 field 27  number of grains   67108864
 field 28  number of grains   134217728
 field 29  number of grains   268435456
 field 30  number of grains   536870912
 field 31  number of grains   1073741824
 field 32  number of grains   2147483648
 field 33  number of grains   4294967296
 field 34  number of grains   8589934592
 field 35  number of grains   17179869184
 field 36  number of grains   34359738368
 field 37  number of grains   68719476736
 field 38  number of grains   137438953472
 field 39  number of grains   274877906944
 field 40  number of grains   549755813888
 field 41  number of grains   1099511627776
 field 42  number of grains   2199023255552
 field 43  number of grains   4398046511104
 field 44  number of grains   8796093022208
 field 45  number of grains   17592186044416
 field 46  number of grains   35184372088832
 field 47  number of grains   70368744177664
 field 48  number of grains   140737488355328
 field 49  number of grains   281474976710656
 field 50  number of grains   562949953421312
 field 51  number of grains   1125899906842624
 field 52  number of grains   2251799813685248
 field 53  number of grains   4503599627370496
 field 54  number of grains   9007199254740992
 field 55  number of grains   18014398509481984
 field 56  number of grains   36028797018963968
 field 57  number of grains   72057594037927936
 field 58  number of grains   144115188075855872
 field 59  number of grains   288230376151711744
 field 60  number of grains   576460752303423488
 field 61  number of grains   1152921504606846976
 field 62  number of grains   2305843009213693952
 field 63  number of grains   4611686018427387904
 field 64  number of grains   -9223372036854775808

C:\tinyscheme-master\src>

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 09, 2014, 11:02:32 PM
John,

Thank you very much for this listing. It shows that GCC cannot cope fully automatically with bitness conversion of the original code. I will install TDM GCC 4.8.1 under my 64-bit Windows 7, and I will take these sources as the basis for making a clean compilation of TS, and I will make all the intermediate test builds myself. So no more PITA for you with your extension module to your ScriptBASIC.

But be forewarned that 4.8.1 links against a thread handler that ships in a separate dll -- libgcc_s_dw2-1.dll. You will have to either ship this dll along with your TS distro (both 32 and 64 bits) or recompile my final sources with some earlier version of 64-bit TDM GCC that went without that multithreaded appendage.
Title: Re: TinyScheme
Post by: JRS on September 09, 2014, 11:08:37 PM
Thanks Mike for all your efforts!

I think TS is becoming our Hello World for 32 to 64 bit migrations.  :)
Title: Re: TinyScheme
Post by: JRS on September 10, 2014, 07:23:58 AM
Quote
So no more PITA for you with your extension module to your ScriptBASIC.

Is this still the plan or did I lose you to FBSL DynLisp?

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 10, 2014, 08:48:14 AM
Why, sure it is! How can I leave you in the middle of the road? DynLisp was mentioned in another thread... :)
Title: Re: TinyScheme
Post by: JRS on September 10, 2014, 09:09:43 AM
Just making sure I didn't lose my Lisping buddy.  ;D
Title: Re: TinyScheme
Post by: RobbeK on September 10, 2014, 10:54:38 AM
Hi John,

"Is it just me or does Lisp seem more popular and feature rich on the Linux side? "

Yes, I think the reason is that Unix is a lot older than Windows , from the early 70s and in the 80s already starting with the X Windows graphical environment, and of course Lisp is older than Unix -- so mainly for windows one has to translate existing Lisps. (which is still somewhat problematic for SBCL ).
I only know Corman Lisp being developed for the Win OS.  (http://www.cormanlisp.com/) , but it may be based on PowerLisp for the Mac.

From the MS side, there has been no interest at all concerning Lisp (they followed the popular line of the moment that every computer is equipped with a basic interpreter/(compiler) ) -- while the classical editor on the Unix systems, EMACS is written in Lisp and interactive with Lisp, and on their turn the intrest in BASIC form the *nix side is also very low...

btw Lisp already did a kind of JIT in 1960's  (fed with IBM punch cards)

it's something as

(define progA (read-punch-cards sourceA))
(define progB (read-punch-cards sourceB))
.
.
(define ActionA (lambda () (eval progA)))  ;;; this does the trick  other languages couldn't do in those days , they just read/ran the code of  the cards in sequence.

best, Rob

 
Title: Re: TinyScheme
Post by: JRS on September 10, 2014, 11:22:31 AM
It only seems logical that BASIC with a Lisp extension is a way to bridge the gap.
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 10, 2014, 12:37:46 PM
John,

As promised, attached please find the 64-bit TDM GCC 4.8.1 stuff. It comes in the /src directory in two flavors -- as a Code::Blocks workspace, for civilized devs, and a simple build_tdm_gcc_481_64.bat file, for geeks. Each one compiles TS faultlessly into a -O3 64-bit executable.

Make sure to cd into /src and run the batch file as Administrator.

On a side note:
-- this -O3 app runs much much faster than the 32-bit build; it does the doubly recursive fibo(35) in 20 secs only against the former 1:30 mins;
-- the latest TDM GCC 4.8.1 recognizes alien %l and %ll formats, reports them as errors, and aborts compilation. It took linuxoids no more than 10 years to become aware of this tiny difference between our platforms. It will take them yet another 10 (20 all in all) to realize that their bloody empty .bss sections in their crooked gcc executables are breaking the integrity of PE headers sticking far beyond their declared section boundaries. ;)

.
Title: Re: TinyScheme
Post by: JRS on September 10, 2014, 12:52:32 PM
You're the man!

Code: [Select]
gcc.exe -Wall -O3 -Wno-unused -fno-strict-aliasing -fno-common  -c dynload.c -o ./obj/dynload.o
gcc.exe -Wall -O3 -Wno-unused -fno-strict-aliasing -fno-common  -c scheme.c -o ./obj/scheme.o
g++.exe  -o tinyscheme.exe ./obj/dynload.o ./obj/scheme.o -s


C:\TS_GCC_64\src>build_tdm_gcc_481_64.bat

C:\TS_GCC_64\src>gcc.exe -Wall -O3 -Wno-unused -fno-strict-aliasing -fno-common  -c dynload.c -o ./obj/dynload.o

C:\TS_GCC_64\src>gcc.exe -Wall -O3 -Wno-unused -fno-strict-aliasing -fno-common  -c scheme.c -o ./obj/scheme.o

C:\TS_GCC_64\src>g++.exe  -o tinyscheme.exe ./obj/dynload.o ./obj/scheme.o -s

C:\TS_GCC_64\src>


Output


C:\TS_GCC_64\src>tinyscheme king.scm
The reward of the King
----------------------

 field 1  number of grains   1
 field 2  number of grains   2
 field 3  number of grains   4
 field 4  number of grains   8
 field 5  number of grains   16
 field 6  number of grains   32
 field 7  number of grains   64
 field 8  number of grains   128
 field 9  number of grains   256
 field 10  number of grains   512
 field 11  number of grains   1024
 field 12  number of grains   2048
 field 13  number of grains   4096
 field 14  number of grains   8192
 field 15  number of grains   16384
 field 16  number of grains   32768
 field 17  number of grains   65536
 field 18  number of grains   131072
 field 19  number of grains   262144
 field 20  number of grains   524288
 field 21  number of grains   1048576
 field 22  number of grains   2097152
 field 23  number of grains   4194304
 field 24  number of grains   8388608
 field 25  number of grains   16777216
 field 26  number of grains   33554432
 field 27  number of grains   67108864
 field 28  number of grains   134217728
 field 29  number of grains   268435456
 field 30  number of grains   536870912
 field 31  number of grains   1073741824
 field 32  number of grains   2147483648
 field 33  number of grains   4294967296
 field 34  number of grains   8589934592
 field 35  number of grains   17179869184
 field 36  number of grains   34359738368
 field 37  number of grains   68719476736
 field 38  number of grains   137438953472
 field 39  number of grains   274877906944
 field 40  number of grains   549755813888
 field 41  number of grains   1099511627776
 field 42  number of grains   2199023255552
 field 43  number of grains   4398046511104
 field 44  number of grains   8796093022208
 field 45  number of grains   17592186044416
 field 46  number of grains   35184372088832
 field 47  number of grains   70368744177664
 field 48  number of grains   140737488355328
 field 49  number of grains   281474976710656
 field 50  number of grains   562949953421312
 field 51  number of grains   1125899906842624
 field 52  number of grains   2251799813685248
 field 53  number of grains   4503599627370496
 field 54  number of grains   9007199254740992
 field 55  number of grains   18014398509481984
 field 56  number of grains   36028797018963968
 field 57  number of grains   72057594037927936
 field 58  number of grains   144115188075855872
 field 59  number of grains   288230376151711744
 field 60  number of grains   576460752303423488
 field 61  number of grains   1152921504606846976
 field 62  number of grains   2305843009213693952
 field 63  number of grains   4611686018427387904
 field 64  number of grains   -9223372036854775808


C:\TS_GCC_64\src>

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 10, 2014, 01:05:52 PM
Glad you like it. :)

It's a pity Rob doesn't run 64 bits. It would be nice to test TS' trigonometry and rounding functions to see if they work well from the point of view of Windows' pseudo long doubles.

Perhaps he can provide some simple test functions in the Scheme dialect to see if the results are consistent.
Title: Re: TinyScheme
Post by: JRS on September 10, 2014, 01:17:58 PM
What would make me ecstatic is getting the TSX and RE extensions to compile under VS/VC and GCC and push it up to the Github repository for this project so everyone can enjoy your hard work.
 
Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 10, 2014, 01:23:18 PM
Oh yeah, I see my hard work is always making you ecstatic. :)
Title: Re: TinyScheme
Post by: JRS on September 10, 2014, 01:37:01 PM
Aren't open source projects great!

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 10, 2014, 01:55:06 PM
Russians call it "riding to the heavens on someone else's back". :)
Title: Re: TinyScheme
Post by: JRS on September 10, 2014, 02:00:07 PM
I didn't see anyone else beside you and I making the effort to do a Windows 64 bit port of TinyScheme. You have the most to gain by being the lead on the Windows front. Please stop thinking I'm taking advantage of you. If you're not having fun than STOP!

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 10, 2014, 02:11:17 PM
Wise men say smilies are instruments for the dumbheads that can't express themselves adequately through normal human speech. Perhaps I'm one of them. I edited my messages. :)
Title: Re: TinyScheme
Post by: JRS on September 10, 2014, 02:23:02 PM
I'm just trying to get the SB TS ext. module working on as many platforms as possible. Windows 64 continues to be a challenge. (for me) We are not alone. Finding and documenting the changes needed to port Windows 32 bit or cross platform open source libraries is a honorable task and many will thank you for your efforts.

Attached is Mike's Windows 64 bit GCC TinyScheme console interpreter. (tinyscheme.exe, init.scm and king.scm)



.
Title: Re: TinyScheme
Post by: JRS on September 10, 2014, 03:55:37 PM
Quote from: Mike
It's a pity Rob doesn't run 64 bits.

Rob,

If you get a FREE Koding.com account, you can run all your favorite Lisp varieties under Ubuntu 64 bit. We can even co-develop with chat in Koding's team collaborative option. Check it out and if you like I can help you install SB and the TS ext. module. (64 bit)

FYI - The GUI part isn't Koding.com stock. I had to install / configure the requirement myself.

.
Title: Re: TinyScheme
Post by: JRS on September 11, 2014, 04:11:36 PM
Mike,

What is your feelings about the TSX & RE extensions being ported to Windows 64 bit? Is it worth your time?

Title: Re: TinyScheme
Post by: Mike Lobanovsky on September 11, 2014, 04:20:19 PM
Frankly, haven't looked into them as of yet.
Title: Re: TinyScheme
Post by: JRS on September 11, 2014, 04:41:23 PM
Okay, just wondering.
Title: Re: TinyScheme
Post by: JRS on September 11, 2014, 08:26:29 PM
Rob,

Another option for you which would give you both Windows and Linux 64 bit is Amazon AWS. If you aren't a current customer they will give you a year of FREE cloud based computing services. You have to give them a credit card but nothing is charged for the first year. With Koding.com all you need is a valid e-mail address.

http://aws.amazon.com/free/

I'm running a medium size instance on AWS EC2 which gives me plenty of horse power and burst when needed.

Here is a sceenshot of SB SDL_gfx running via a SSH connection.



.
Title: Re: TinyScheme
Post by: RobbeK on September 12, 2014, 12:50:43 AM
Thanks John,

I'll give Koding.com a try !

best Rob
Title: Re: TinyScheme
Post by: JRS on September 12, 2014, 01:58:13 AM
Heads-up, Koding.com seem to be having an issue at the moment bringing up terminals. (VM's) They should have it resolve soon. You will like Koding.com (when its working) and the freedom it gives you to configure your own VM.
Title: Re: TinyScheme
Post by: JRS on September 12, 2014, 10:08:26 AM
My Koding .com VM is working again. Try setting up a free account and let us know what you think.

Title: Re: TinyScheme
Post by: RobbeK on September 13, 2014, 10:57:45 AM
Thanks John, 

member of the gang now ,    ( robbek is the name there )

best Rob !! 
Title: Re: TinyScheme
Post by: JRS on September 13, 2014, 11:22:48 AM
Quote
member of the gang now ,

Welcome to the Koding family!

Let me know if you need a hand with anything.

FYI: localhost = 0.0.0.0 in your VM.



Title: Re: TinyScheme
Post by: JRS on September 15, 2014, 09:22:05 PM
Rob,

Curious if you were able to get all your favorite Lisp languages running on Koding.com in 64 bit?

John
Title: Re: TinyScheme
Post by: RobbeK on September 16, 2014, 01:14:23 AM
Hi John,

Not yet ...   I have to finish something else first, but it is almost done ,  i'll update the moment been there


best regards, Rob
Title: Re: TinyScheme
Post by: JRS on November 14, 2014, 12:06:30 PM
Rob,

I would like to experiment with the TinyScheme SB extension module generating statistical lists that the SB SQLite extension module would store. Finally I would like to use this stored SQL data to generate graphics with the SDL_gfx SB extension module. Maybe we can add some O2 DLLC magic to gain a little speed. Charles is already working on a table/matrix feature that might come in handy eliminating the SQLite part.

I gave your/Mike text Mandelbrot example a try since the rebuild of my Linux system.

Code: Script BASIC
  1. ' Character Mandelbrot
  2.  
  3. IMPORT ts.inc
  4.  
  5. sc = TS_New()
  6. TS_Cmd sc, "(load \"init.scm\")"
  7. mbrot = """
  8. (newline)
  9. (newline)
  10. (display "Ascii Mandelbrot TinyScheme") (newline)
  11. (display "---------------------------") (newline)
  12.  
  13. (define sq
  14.   (lambda (x) (* x x)))
  15.  
  16. (define (1+ x) (+ x 1))
  17. (define (1- x) (- x 1))
  18.  
  19. (define level
  20.  (lambda (i x y rc ic it orb)
  21.   (if (or (= i it) (> orb 4)) i
  22.    (level (1+ i) (+ rc (- (sq x) (sq y))) (+ ic (* 2 x y)) rc ic it (+ (sq x) (sq y))))))
  23.  
  24. (define mlevel
  25.   (lambda (L)
  26.     (level 0 (cadr L) (car L) (cadr L) (car L) 11 0)))
  27.  
  28. (define (main)
  29.   (let ((cnt 0) (lvl 0) (xo -1.7) (yo -2.3) (dz 0.1) )
  30.     (do ((i 0 (1+ i)))
  31.         ((= i 30))
  32.        (do ((j 0 (1+ j)))
  33.            ((= 30 j))
  34.              (set! lvl (mlevel (list (+ xo (* i dz)) (+ yo (* j dz)) )))
  35.              (if (< lvl 10)
  36.                   (begin (display lvl) (display " "))
  37.                   (display lvl))
  38.              (set! cnt (1+ cnt))
  39.              (when (= 30 cnt)
  40.                 (set! cnt 0)
  41.                 (newline))
  42. ))))
  43.  
  44. (main)
  45. """  
  46. PRINT TS_Cmd(sc, mbrot),"\n"
  47. TS_Close sc
  48.  

Output

jrs@laptop:~/sb/sb22/TS$ time scriba mbrot.sb


Ascii Mandelbrot TinyScheme
---------------------------
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2
1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2
1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3
1 1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3
1 1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3
1 1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3
1 1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4
1 1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4
1 1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4
1 1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4
1 1 1 1111111111111111111111111111111111111111111111117 5 4
1 1 1 1 4 4 6 6 7 1111111111111111111111111111111111118 5 4
1 1 1 1 4 4 4 5 5 6 8 11111111111111111111111111111111115 4
1 1 1 1 3 4 4 4 5 5 7 111111119 1111111111111111111111116 4
1 1 1 1 3 3 3 3 4 5 7 7 7 7 7 7 11111111111111111111119 5 4
1 1 1 1 2 3 3 3 3 3 4 5 5 5 5 6 8 111111111111111111117 5 3
1 1 1 1 2 3 3 3 3 3 3 3 4 4 5 5 6 11111111111111111111114 3
1 1 1 1 1 2 3 3 3 3 3 3 3 4 4 4 5 7 8 8 101111119 6 6 5 4 3
1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 8 1111116 5 5 4 3 3
1 1 1 1 1 1 2 3 3 3 3 3 3 3 3 4 4 4 4 5 6 9 118 5 4 4 3 3 3
1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 5 7 9 114 4 3 3 2 2
1 1 1 1 1 1 1 2 2 2 3 3 3 3 3 3 3 3 4 4 4 115 4 4 3 3 2 2 2
1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2

real   0m0.634s
user   0m0.629s
sys    0m0.004s
jrs@laptop:~/sb/sb22/TS$


The Script BASIC SDL_gfx extension module is also working fine. (see attached)

Code: Script BASIC
  1. ' ScriptBasic GFX - Alpha Bezier Curve
  2.  
  3. IMPORT gfx.inc
  4.  
  5. ' Random Value Arrays
  6. scrn = gfx::Window(640, 480, "Script BASIC SDL_gfx - Alpha Bezier")
  7. RANDOMIZE(gfx::Time())
  8. FOR i = 0 TO 512
  9.   rx[i] = RND() % 640/2
  10.   rxx[i] = 640/2 + rx[i]  
  11.   ry[i] = 60 + RND() % 480 - 80
  12.   lw[i] = 2 + RND() % 7
  13.   rr[i] = RND() AND  255
  14.   rg[i] = RND() AND  255
  15.   rb[i] = RND() AND  255
  16.   af = rx[i] / 640
  17.   ra[i] = INT(255 * af)
  18. NEXT
  19. ts = gfx::Time()
  20. FOR i = 0 TO 512-3 STEP 3
  21.   a1[0] = rxx[i]
  22.   a1[1] = rxx[i + 1]
  23.   a1[2] = rxx[i + 2]
  24.   a2[0] = ry[i]
  25.   a2[1] = ry[i + 1]
  26.   a2[2] = ry[i + 2]
  27.   gfx::bezierRGBA scrn, a1, a2, 3, 100, rr[i], rg[i], rb[i], ra[i]
  28. NEXT
  29. te = gfx::Time()
  30. gfx::stringColor scrn, 20, 15,"Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xffffffff
  31. gfx::Update
  32. WHILE gfx::KeyName(1) <> "+escape"
  33. WEND
  34. gfx::Close
  35.  

Another option is to use the new IUP GL Controls (http://webserver2.tecgraf.puc-rio.br/iup/examples/C/glcontrols.c). This may be preferred as DLLC allows multi-threading IUP SB sessions with a common message handler able to call SB functions/subs.

(http://webserver2.tecgraf.puc-rio.br/iup/en/gl/glcanvascube.png)

Can you help fill in the holes with defining the model and generating the TinyScheme lists?

John

.
Title: Re: TinyScheme (Chicken)
Post by: JRS on November 14, 2014, 08:52:15 PM
Rob,

I built the latest development release of Chicken on my Linux 14.04 64 bit box.


jrs@laptop:~/chicken-4.9.0rc1$ ./csi

CHICKEN
(c) 2008-2014, The Chicken Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.9.0rc1 (rev 3cf1967)
linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
compiled 2014-04-17 on hd-t1179cl (Linux)

#;1>


This looks interesting but I don't know how/where the IUP interface can be found.

Tutorial on the Iup Graphical User Interface toolkit (http://wiki.call-cc.org/iup-tutor#initial-version)
Title: Re: TinyScheme
Post by: JRS on November 17, 2014, 07:09:22 PM
I was finally able to get the IUP GL Controls demo compiled on Linux. (with Antonio's help) There was a #ifdef causing skipping of code in the example.  :-\


jrs@laptop:~/sb/c_ode$ ./glcontrols
Vendor: Intel Open Source Technology Center
Renderer: Mesa DRI Intel(R) Ironlake Mobile
Version: 2.1 Mesa 10.1.3
ACTION_CB(gltoggle, state=1) NAME=toggle5
...


Has anyone heard from Rob lately?



.
Title: Re: TinyScheme
Post by: Mike Lobanovsky on November 17, 2014, 10:51:50 PM
Quote
Has anyone heard from Rob lately?
Nope.
Title: Re: TinyScheme
Post by: JRS on November 17, 2014, 11:12:18 PM
Mike,

I'm trying to bring TinyScheme and IUP GL Controls together for a GUI Lisp example. Do you have a TinyScheme example that would generate delimited lists that I could translate to a graphic representation? I was thinking the Mandelbrot iterator I converted as a SDL_gfx ext. module function to get started.

John
Title: Re: TinyScheme
Post by: Mike Lobanovsky on November 17, 2014, 11:29:23 PM
Er, no John, I'm not that advanced in Scheme yet. But I think you can use Rob's ASCII Mandelbrot too if its output numbers are table mapped to distinct colors of some blobs (e.g. square or circular shapes) drawn on the IUP OpenGL canvas.

AFAIK there are no instruments in IUP to draw primitives per se (dots, lines, shapes, etc.), which means you will also have to provide some form of direct communication between your Scheme and the OpenGL library's API in order to be able to draw on the IUP OpenGL canvas. I'm not sure if TinyScheme has such functionality but I think Chicken should have it implemented by now.

This Chicken+IUP interface seems interesting. :)
Title: Re: TinyScheme
Post by: JRS on November 17, 2014, 11:34:12 PM
I have to agree that the IUP OpenGL interface (other than their new controls) is raw. I'm better off sticking with SDL_gfx for the graphics interface.

Here is a very early attempt at using IUP canvas primitives to create a Mandelbrot Set.

(http://files.allbasic.info/ScriptBasic/mbs_frac.png)

Code: Script BASIC
  1. IMPORT iup.bas
  2.  
  3. Iup::Open()
  4.  
  5. ican = Iup::Canvas()
  6. Iup::SetAttribute(ican, "RASTERSIZE", "800x600")
  7. Iup::SetAttribute(ican, "BORDER", "NO")
  8.  
  9. dlg = Iup::Dialog(Iup::Vbox(ican))
  10. Iup::SetAttribute(dlg, "TITLE", "Mandelbrot Set")
  11.  
  12. Iup::Map(dlg)
  13.  
  14. ccan = CD::CreateCanvas(CD::ContextIup(), ican)
  15.  
  16. Iup::Show(dlg)
  17.  
  18. przelx = 3 / 800
  19. przely = 2 / 600
  20.  
  21. FOR x = 1 TO 800
  22.   FOR y = 1 TO 600
  23.     a = 0
  24.     b = 0
  25.     c = 0
  26.     x2 = (przelx * x) - 2
  27.     y2 = (przely * y) - 1
  28.     petla:
  29.     a2 = a * a - b * b
  30.     b2 = 2 * a * b
  31.     a = a2 + x2
  32.     b = b2 + y2
  33.     z = a * a + b * b
  34.     IF z < 4 AND c < 255 THEN
  35.       c = c + 1
  36.       GOTO petla
  37.     END IF
  38.     IF c = 255 THEN
  39.       pixclr = CD::EncodeColor(0, 0, 0)
  40.     ELSE
  41.       g = 255 - c
  42.       pixclr = CD::EncodeColor(g, g, g)
  43.       ' Color version
  44.      ' pixclr = (g+64) * g * (g+16)
  45.    END IF
  46.     CD::CanvasPixel(ccan, x, y, pixclr)
  47.   NEXT y
  48. NEXT x
  49.  
  50. Iup::MainLoop()
  51. Iup::Close()
  52.  
Title: Re: TinyScheme
Post by: Mike Lobanovsky on November 17, 2014, 11:49:02 PM
I'm talking about general ability of whatever Scheme you use to call a shared object's API, and I'm not sure if TinyScheme is at all able to call alien C libraries (.so or .dll). OTOH I think Chicken can do it, so both IUP+SDL and IUP+OpenGL seem feasible: depending on your preference, you just create an IUP dialog window and assign an SDL or OpenGL canvas to it and then use the corresponding SDL or OpenGL API's to draw on it.

P.S. Oh, so you know how to draw on an IUP canvas or at least set pixels on it, don't you?
Title: Re: TinyScheme
Post by: JRS on November 17, 2014, 11:58:21 PM
I'm happy with the TinyScheme interface the way it works. SB will create TS functions and call them. The results (a string) will be SPLITA to an array and processed by SDL_gfx. (the plan anyways)

IUP has the CD (Canvas Draw (http://webserver2.tecgraf.puc-rio.br/cd/)) library you need to download separately.
Title: Re: TinyScheme
Post by: Mike Lobanovsky on November 18, 2014, 12:03:32 AM
Understood.

And thanks for the tip on Canvas Draw; it somehow slipped my attention.
Title: Re: TinyScheme
Post by: RobbeK on February 08, 2015, 04:18:31 AM
TS and foreign functions :


https://github.com/ignorabimus/tinyscheme-ffi


best, Rob
Title: Re: TinyScheme
Post by: JRS on February 08, 2015, 09:35:09 AM
Cool Rob!

I'll give it a try with the Script BASIC extension module.

Thanks for the link!
Title: Re: TinyScheme
Post by: JRS on February 08, 2015, 12:10:50 PM
This is a Windows only solution.    :-[

If this could be adapted to work with Linux, I could call SB functions & subs, access variables, ... from within a TinyScheme script. I have the 64 bit  libffi installed already.

Do you have Script BASIC installed on your Linux or Windows partitions?
Title: Re: TinyScheme
Post by: RobbeK on February 10, 2015, 07:54:32 AM
Hi John,

Only on the Win32 part. for the moment , not sure I have a 32bit Linux version around here (iirc you compiled it 64bit ??)

best, Rob
(it would be very handy to have one or the other -- I can write DLLs / SOs in FreePascal , TinyScheme makes an easy bundled standalone  -- I already wrote Complex Numbers and 2D graphics libs (very fast ones) )
Title: Re: TinyScheme
Post by: JRS on February 10, 2015, 09:21:05 AM
The library refers to a Windows handle which stopped any further investigation of a Linux conversion for me.