Author Topic: Lisp in Basic  (Read 208392 times)

0 Members and 2 Guests are viewing this topic.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #540 on: August 18, 2014, 03:46:59 PM »
I still see no response to my note on Windows line breaks. Please read my previous message but one now.

JRS

  • Guest
Re: Lisp in Basic
« Reply #541 on: August 18, 2014, 03:58:33 PM »
Run after changing Rob file to Linux linefeed only termination. (Ubuntu 32 bit)

Code: [Select]
jrs@U32VB:~/sb22/sblisp$ ../bin/scriba lisp.sb Xblisp002.txt
SBLisp - Scheme BASIC Lisp

(define divisor?
  (lambda (p q)
ERROR: Read.
ERROR: Problem in file Xblisp002.txt
ERROR: Bad type.
0](quit)
jrs@U32VB:~/sb22/sblisp$

Here is running the same but SBLisp as a standalone.

Code: [Select]
jrs@U32VB:~/sb22/sblisp$ ./SBLisp Xblisp002.txt
SBLisp - Scheme BASIC Lisp

(define divisor?
  (lambda (p q)
ERROR: Read.
ERROR: Problem in file Xblisp002.txt
ERROR: Bad type.
0]

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #542 on: August 18, 2014, 04:03:39 PM »
OK John,

Please where can I download precompiled 32- and 64-bit SB distros for Linux so I don't have to pull in all the dependencies and compile SB from the sources myself?

JRS

  • Guest
Re: Lisp in Basic
« Reply #543 on: August 18, 2014, 04:08:27 PM »
From the Script BASIC forum 2.2 beta release sticky on the download board.

Here is the link

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #544 on: August 18, 2014, 04:11:06 PM »
Thank you John,

I'll come back later when I have anything to say. :)

JRS

  • Guest
Re: Lisp in Basic
« Reply #545 on: August 18, 2014, 04:11:58 PM »
Thanks Mike for going the extra mile!

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #546 on: August 18, 2014, 06:52:21 PM »
Hello John,

Your (fibonacci 20) worked only because it was a Linux file that you typed in yourself (remember (( n 2) typos?). Therefore there were never any Windoze carriage returns in there. Rob's file was originally Windoze and you failed to re-save it without CR's as I asked you to. You have to have a special editor that has this capability as an explicit feature to select. Otherwise mere re-saving it under Linux doesn't remove the CR's.

So the problem was in CHOMP(). Its behavior under Linux and Windows is different. It chomps full CRLF's under Windows but only LF's under Linux leaving CR's in place. Linuxoid TRIM() doesn't trim Windoze CR's either. It isn't important in the interactive mode where only the respective symbols are generated in response to Enter but it's a killer in the file load mode.

I fixed this bug and now SBLisp can swallow any line endings in both worlds. I also made use of your -D flag to add a couple special printouts to the ERROR cases. Thanks for that option, it's gonna be useful in the future.

So have a look at the picture and test the new lisp.sb then upload it to the repo, please.

(beware: now that you've got me hooked on Linux and are playing truant, you may easily lose your leading place in the acknowledgment blurb, hehe...)

.

JRS

  • Guest
Re: Lisp in Basic
« Reply #547 on: August 18, 2014, 07:09:10 PM »
I'm glad it wasn't a SB thing. I deal with the MS/Linux line terminator and \/ issue all the time.

I'm glad you're liking Linux again.

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb Xblisp002.txt
SBLisp - Scheme BASIC Lisp

(define divisor?
  (lambda (p q)
   (let (( x (/ p q)))
     (if (= x (floor x)) 1 0 ))))
DIVISOR?
(define more-divisorsx
  (lambda ( i x nr)
    (if (or (> i (/ x 2)) (> nr 0 ) ) nr
      (more-divisorsx (+ i 1) x (+ nr (divisor? x i))))))
MORE-DIVISORSX
(define more-divisors
  (lambda (x)
   (more-divisorsx 2 x 0)))
MORE-DIVISORS
(define prime?
   (lambda (x)
     (if (= (more-divisors x) 0 ) x 0 )))
PRIME?
(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))
MAKE-LISTX
(define make-list
     (lambda (x)
      (reverse (make-listx 2 x '() ))))
MAKE-LIST
(define sq (make-list 300))
SQ
(define main
  (lambda ()
    (newline)
    (newline)
    (newline)
    (newline)
    (print 'SBLisp ) (newline)
    (print '------ ) (newline) (newline)
    (print 'List= )
    (print sq)
    (newline)
    (newline)
    (print 'Filtering_primes_by_mapping)
    (newline)
    (let (( res (map prime? sq)))
      (print res)
      (newline)
      (print '....finished )
      (print '..... )
)))
MAIN
(main)




SBLISP
------

LIST=(2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299)

FILTERING_PRIMES_BY_MAPPING
(2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 0 0 0 0 53 0 0 0 0 0 59 0 61 0 0 0 0 0 67 0 0 0 71 0 73 0 0 0 0 0 79 0 0 0 83 0 0 0 0 0 89 0 0 0 0 0 0 0 97 0 0 0 101 0 103 0 0 0 107 0 109 0 0 0 113 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0 0 0 131 0 0 0 0 0 137 0 139 0 0 0 0 0 0 0 0 0 149 0 151 0 0 0 0 0 157 0 0 0 0 0 163 0 0 0 167 0 0 0 0 0 173 0 0 0 0 0 179 0 181 0 0 0 0 0 0 0 0 0 191 0 193 0 0 0 197 0 199 0 0 0 0 0 0 0 0 0 0 0 211 0 0 0 0 0 0 0 0 0 0 0 223 0 0 0 227 0 229 0 0 0 233 0 0 0 0 0 239 0 241 0 0 0 0 0 0 0 0 0 251 0 0 0 0 0 257 0 0 0 0 0 263 0 0 0 0 0 269 0 271 0 0 0 0 0 277 0 0 0 281 0 283 0 0 0 0 0 0 0 0 0 293 0 0 0 0 0 0)
....FINISHED..........
T
0]


Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #548 on: August 18, 2014, 07:24:31 PM »
I'm glad it wasn't a SB thing.
But it is! Actually it's a design fault! Why don't I have to think about where my files come from? And why my TRIM() would chomp and trim everything that's whitespace no matter where it comes from -- Windows, Unix, or Mac?!

Stop being chauvinistic, John, and if you have time, spend it on fixing the SB sources to forget about your linebreak headaches once and for all.

Glad to see it working on your machine. Means I didn't spend yet another sleepless night for nothing. :)

JRS

  • Guest
Re: Lisp in Basic
« Reply #549 on: August 18, 2014, 07:27:23 PM »
Thanks Mike for tracking down the issue.

Quote from: Mike
beware: now that you've got me hooked on Linux and are playing truant, you may easily lose your leading place in the acknowledgment blurb, hehe...

Don't complain. You're getting major action in the commit comments.  :P
« Last Edit: August 18, 2014, 08:38:04 PM by John »

JRS

  • Guest
Re: Lisp in Basic
« Reply #550 on: August 18, 2014, 11:57:07 PM »
Hey Mike,

That Windows 7 looking Linux you're using is pretty slick!

Here is Debian noroot running on my Samsung Galaxy  Tab 2 10.1 tablet. This is the best version of Linux running on Android so far. No VNC as X11 is done in SDL. I was able to get Script BASIC to compile native ARM from source but realized I didn't use the source we tweaked for the Android Linux (ARM) version. I'll recompile tomorrow with the correct source.




.
« Last Edit: August 19, 2014, 12:24:12 AM by John »

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #551 on: August 19, 2014, 12:01:36 AM »
A big "step"

step is the perfect word for this.
I could set up (range x) for the lib (the idea comes from Racket Scheme).
This is the mother of iteration ....

see source ,   can do (newlines x) now , if it were iterative ...

best Rob

(oops, yes , I use LispIDE for building the source -- it gives matching paren's , is this a problem ??)

.

JRS

  • Guest
Re: Lisp in Basic
« Reply #552 on: August 19, 2014, 12:06:59 AM »
Xblisp003.txt
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb Xblisp003.txt
SBLisp - Scheme BASIC Lisp

(define divisor?
  (lambda (p q)
   (let (( x (/ p q)))
     (if (= x (floor x)) 1 0 ))))
DIVISOR?
(define more-divisorsx
  (lambda ( i x nr)
    (if (or (> i (/ x 2)) (> nr 0 ) ) nr
      (more-divisorsx (+ i 1) x (+ nr (divisor? x i))))))
MORE-DIVISORSX
(define more-divisors
  (lambda (x)
   (more-divisorsx 2 x 0)))
MORE-DIVISORS
(define prime?
   (lambda (x)
     (if (= (more-divisors x) 0 ) x 0 )))
PRIME?
(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))
MAKE-LISTX
(define make-list
     (lambda (x)
      (reverse (make-listx 2 x '() ))))
MAKE-LIST
(define range
  (lambda (x)
    (reverse (make-listx 0 x '() ))))
RANGE
(define newlines
  (lambda (x)
    (map newline (range x))
      'ok ))
NEWLINES
(define sq (make-list 200))
SQ
(define main
  (lambda ()
    (newlines 10)
    (newline)
    (print 'SBLisp ) (newline)
    (print '------ ) (newline) (newline)
    (print 'List= )
    (print sq)
    (newline)
    (newline)
    (print '"Filtering primes by mapping")
    (newline)
    (let (( res (map prime? sq)))
      (print res)
      (newline)
      (print '....finished )
      (print '..... )
)))
MAIN
(main)











SBLISP
------

LIST=(2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199)

FILTERING PRIMES BY MAPPING
(2 3 0 5 0 7 0 0 0 11 0 13 0 0 0 17 0 19 0 0 0 23 0 0 0 0 0 29 0 31 0 0 0 0 0 37 0 0 0 41 0 43 0 0 0 47 0 0 0 0 0 53 0 0 0 0 0 59 0 61 0 0 0 0 0 67 0 0 0 71 0 73 0 0 0 0 0 79 0 0 0 83 0 0 0 0 0 89 0 0 0 0 0 0 0 97 0 0 0 101 0 103 0 0 0 107 0 109 0 0 0 113 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0 0 0 131 0 0 0 0 0 137 0 139 0 0 0 0 0 0 0 0 0 149 0 151 0 0 0 0 0 157 0 0 0 0 0 163 0 0 0 167 0 0 0 0 0 173 0 0 0 0 0 179 0 181 0 0 0 0 0 0 0 0 0 191 0 193 0 0 0 197 0 199)
....FINISHED..........
T
0]


Nice to see this thing actually working.  8)
« Last Edit: August 19, 2014, 12:34:38 AM by John »

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #553 on: August 19, 2014, 12:59:35 AM »
Et voilĂ  , messieurs ... 

...   the "iterator"   

the operator must be quoted !!     like     (iterate 'newline 5)    8)

best Rob

oops, yes ..  the source is it QB ??  -- can't you wring/wrench it through something as QB64 / FB to give it more speed ??
(now filtering the zero's -- then I'm off (probably) till this evening

.

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #554 on: August 19, 2014, 01:29:28 AM »
With zero removal and the "glorious  iterator" in action ...   8)

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

(define divisor?
  (lambda (p q)
   (let (( x (/ p q)))
     (if (= x (floor x)) 1 0 ))))


(define more-divisorsx
  (lambda ( i x nr)
    (if (or (> i (/ x 2)) (> nr 0 ) ) nr
      (more-divisorsx (+ i 1) x (+ nr (divisor? x i))))))

(define more-divisors
  (lambda (x)
   (more-divisorsx 2 x 0)))

(define prime?
   (lambda (x)
     (if (= (more-divisors x) 0 ) x 0 )))

(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))

(define make-list
     (lambda (x)
      (reverse (make-listx 2 x '() ))))

(define range
  (lambda (x)
    (reverse (make-listx 0 x '() ))))

(define sq (make-list 200))

(define iterate
  (lambda (op it)
    (map (eval op) (range it))
  T ))

(define filter-zeroesx
   (lambda (L M)
     (if (= (length L) 0) M
         (if (> (car L) 0 ) (filter-zeroesx (cdr L) (cons (car L) M))
                            (filter-zeroesx (cdr L) M )))))

(define filter-zeroes
    (lambda (L)
      (filter-zeroesx L '() )))


(define main
  (lambda ()
    (iterate 'newline 10)
    (newline)
    (print 'SBLisp ) (newline)
    (print '------ ) (newline) (newline)
    (print 'List= )
    (print sq)
    (newline)
    (newline)
    (print '"Filtering primes by mapping")
    (newline)
    (let (( res (map prime? sq)))
      (print res)
      (iterate 'newline 3)
      (print '"Removing the zeroes") (newline)
      (print (reverse (filter-zeroes res)))
      (newline)
      (print '....finished )
      (print '..... )
)))

(main)

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

best , Rob ...  the (reverse ..  )   because it are all FILO operations ...   first in - last out
addendum -- added 006 which does proper printing too.
Is it auto-GC , or do I have to code it ????

.
« Last Edit: August 19, 2014, 03:22:44 AM by RobbeK »