Author Topic: Lisp in Basic  (Read 208154 times)

0 Members and 3 Guests are viewing this topic.

JRS

  • Guest
Re: Lisp in Basic
« Reply #225 on: August 07, 2014, 05:47:48 PM »
I was able to fix the problem with getting a ERROR: Read. if the script had extra blank lines at the end. What I did to fix this is if the position pointer exceed the input buffer length, I told SBLisp to go read another line and force the EOF() to kick in. The Ave.scm file had two extra blank lines at the end of the script.

GetNextToken:
Code: [Select]
  IF ipos > LEN(ibuf) THEN
'   PRINT "ERROR: Read.\n"
'   GOTO HandleError
    GOTO GetLine
  END IF

Testing
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
0](load 'Ave.scm)
Ave.scm  1
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE

(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T



T
0](quit)
Bye!
jrs@laptop:~/sb/sb22/sblisp$

« Last Edit: August 07, 2014, 08:03:24 PM by John »

JRS

  • Guest
Re: Lisp in Basic
« Reply #226 on: August 07, 2014, 06:30:47 PM »
There still seems to be a problem with the blank lines at the end. If I have 2 extra blank lines, it works. (don't like the 2 for 1 PRINT though) If I use only one blank line, I get this error. ERROR: Problem in file Ave.scm  :o

Update

I got it to work with only one blank like and displaying as I would expect. The problem is I don't see the second T symbol which I still don't understand it's purpose. (true response to what?)

Code: [Select]
CheckDot:
  ipos+=1
  IF ipos > LEN(ibuf) THEN
'   PRINT "ERROR: Read.\n"
'   GOTO HandleError
    GOTO GetLine
  END IF

...

HandleError:
  IF lispfilenum <> 0 THEN
'   PRINT "ERROR: Problem in file ", lispfilename, "\n"

Update Mike said he will resolve this globally for both SB & FBSL.
« Last Edit: August 07, 2014, 08:13:15 PM by John »

JRS

  • Guest
Re: Lisp in Basic
« Reply #227 on: August 07, 2014, 09:35:35 PM »
I've added an experimental startup command line script option. It allowed me to time the script execution which I couldn't do before. (SB only has 1 sec. resolution by default) I'm not pushing this to Bitbucket until Mike has a look. A (quit) is required in your command line script to exit SBLisp after completion otherwise it drops to a #] prompt.

Code: [Select]
' The original author of this code is Arthur Nunes-Harwitt

cmdln = COMMAND()
IF LEN(cmdln) THEN
  cmdflg = TRUE
ELSE
  cmdflg = FALSE
END IF

...

GetLine:
  IF cmdflg THEN
    ibuf = "(load '" & cmdln & ")"
    ipos = 1
    cmdflg = FALSE
    bsd -=1
    RETURN
  END IF

Testing
Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ time scriba lisp.sb Ave.scm
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE

(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
(quit)
Bye!

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

Something a bit more demanding.

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ time scriba lisp.sb rectest.scm
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
(define rectest (lambda (x)
(cond ((<= x (* 1000)) (print x) (print '_) (rectest (+ x 1))))
))
RECTEST

(rectest 1)
1_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_GC start GC done.
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_300_301_302_303_304_305_306_307_308_309_310_311_312_313_314_315_316_317_318_319_320_321_322_323_324_325_326_327_328_329_330_331_332_333_334_335_336_337_338_339_GC start GC done.
340_341_342_343_344_345_346_347_348_349_350_351_352_353_354_355_356_357_358_359_360_361_362_363_364_365_366_367_368_369_370_371_372_373_374_375_376_377_378_379_380_381_382_383_384_385_386_387_388_389_390_391_392_393_394_395_396_397_398_399_400_401_402_403_404_405_406_407_408_409_410_411_412_413_414_415_416_417_418_419_420_421_422_423_424_425_426_427_428_429_430_431_432_433_434_435_436_437_438_439_440_441_442_443_444_445_446_447_448_449_450_451_452_453_454_455_456_457_458_459_460_461_462_463_464_465_466_467_468_469_470_471_472_473_474_475_476_477_478_479_480_481_482_483_484_485_486_487_488_489_490_491_492_493_494_495_496_497_498_499_500_501_502_503_504_505_506_507_508_509_GC start GC done.
510_511_512_513_514_515_516_517_518_519_520_521_522_523_524_525_526_527_528_529_530_531_532_533_534_535_536_537_538_539_540_541_542_543_544_545_546_547_548_549_550_551_552_553_554_555_556_557_558_559_560_561_562_563_564_565_566_567_568_569_570_571_572_573_574_575_576_577_578_579_580_581_582_583_584_585_586_587_588_589_590_591_592_593_594_595_596_597_598_599_600_601_602_603_604_605_606_607_608_609_610_611_612_613_614_615_616_617_618_619_620_621_622_623_624_625_626_627_628_629_630_631_632_633_634_635_636_637_638_639_640_641_642_643_644_645_646_647_648_649_650_651_652_653_654_655_656_657_658_659_660_661_662_663_664_665_666_667_668_669_670_671_672_673_674_675_676_677_678_679_GC start GC done.
680_681_682_683_684_685_686_687_688_689_690_691_692_693_694_695_696_697_698_699_700_701_702_703_704_705_706_707_708_709_710_711_712_713_714_715_716_717_718_719_720_721_722_723_724_725_726_727_728_729_730_731_732_733_734_735_736_737_738_739_740_741_742_743_744_745_746_747_748_749_750_751_752_753_754_755_756_757_758_759_760_761_762_763_764_765_766_767_768_769_770_771_772_773_774_775_776_777_778_779_780_781_782_783_784_785_786_787_788_789_790_791_792_793_794_795_796_797_798_799_800_801_802_803_804_805_806_807_808_809_810_811_812_813_814_815_816_817_818_819_820_821_822_823_824_825_826_827_828_829_830_831_832_833_834_835_836_837_838_839_840_841_842_843_844_845_846_847_848_849_GC start GC done.
850_851_852_853_854_855_856_857_858_859_860_861_862_863_864_865_866_867_868_869_870_871_872_873_874_875_876_877_878_879_880_881_882_883_884_885_886_887_888_889_890_891_892_893_894_895_896_897_898_899_900_901_902_903_904_905_906_907_908_909_910_911_912_913_914_915_916_917_918_919_920_921_922_923_924_925_926_927_928_929_930_931_932_933_934_935_936_937_938_939_940_941_942_943_944_945_946_947_948_949_950_951_952_953_954_955_956_957_958_959_960_961_962_963_964_965_966_967_968_969_970_971_972_973_974_975_976_977_978_979_980_981_982_983_984_985_986_987_988_989_990_991_992_993_994_995_996_997_998_999_1000_()
(quit)
Bye!

real 0m1.441s
user 0m1.428s
sys 0m0.008s
jrs@laptop:~/sb/sb22/sblisp$
« Last Edit: August 07, 2014, 10:31:37 PM by John »

JRS

  • Guest
Re: Lisp in Basic
« Reply #228 on: August 07, 2014, 10:45:28 PM »
I was trying some of the examples in the Lisp in BASIC docs and ran into a discrepancy. (last expression)

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
0](let ((x 5)) (+ x 1))
6
0](+ '5 '6)
11
0](/ 12 2 3)
0.666667
0]

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ mit-scheme
MIT/GNU Scheme running under GNU/Linux
Type `^C' (control-C) followed by `H' to obtain information about interrupts.

Copyright (C) 2014 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Image saved on Saturday May 17, 2014 at 2:39:25 AM
  Release 9.2 || Microcode 15.3 || Runtime 15.7 || SF 4.41 || LIAR/x86-64 4.118 || Edwin 3.116

1 ]=> (/ 12 2 3)

;Value: 2

1 ]=>

JRS

  • Guest
Re: Lisp in Basic
« Reply #229 on: August 08, 2014, 07:32:52 AM »
Why MIT switched from Scheme to Python

Q. Costanza asked Sussman why MIT had switched away from Scheme for their introductory programming course?

A. Well, said Sussman, it probably just had a library already implemented for the robotics interface, that was all.

Once again, right place, right time and a current need is all that matters to define the future.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #230 on: August 08, 2014, 09:56:29 AM »
A quick overview of currently known issues:

1. Yes, more than 1 extra blank line at the end of the file make the LISP parser choke in QB45, FBSL and SB alike. This signifies an initial design fault, supposedly, the inability to correctly intercept an EOF event. The lookahead depth in the parsing loop is 1 char only. There's no looping in an empty line; no looping -> no lookahead -> no EOF interception.

2. (/ A B C) and (- A B C) yield trash in QB45, FBSL and SB alike. (+ A B C) and (* A B C) are correct. Another initial design bug.

3. BASIC LISP's T stands for TRUE, () stands for FALSE. Every math or logical evaluation sends its result to the console transparently without an explicit (print something). The explicit print can additionally enforce LISP to output data which isn't part of the evaluation process.

LISP's "evaluation" is what we usually call "execution" in normal human speech. Implicit evaluation is applied to everything that is enclosed in a pair of matching parentheses. Apart from implicit evaluation, LISP also has an explicit (eval [']something) command that additionally returns whatever an executable something has already returned, or turns 'something into an executable and returns only its own evaluation of this otherwise non-executable literal.

From the LISP perspective, execution of a program file as a whole is a command to (eval 'string_literal_with_entire_file_contents). It adds a trailing T (TRUE) to the console output to denote successful completion of the eval command. Failure to evaluate 'something would result in () (FALSE) if only the evaluation process didn't trigger some other error that LISP is responsive to.

In other words, T and () serve as program success/failure return codes in LISP file evaluation.

I find this behavior logically reasonable and I wouldn't fight to suppress it.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #231 on: August 08, 2014, 12:15:09 PM »
Issue 1 fixed!

John,

Will you please undo your repo sources of SBLisp so that I could use them for my future submissions here? Thank you.

Until then please just change the following notation to your SBLisp's equivalent naming convention:

Code: [Select]
GetLine:
IF LispFileNum=0 THEN
PRINT LTRIM(FORMAT("%~##~",OPAREN)), "]"
LINE INPUT I
I = CHOMP(I)
IF ASC(I) = undef THEN GOTO GetLine
IPOS = 1
ELSE
IF NOT EOF(LispFileNum) THEN
LINE INPUT# LispFileNum, I
I = CHOMP(I)
IF ASC(I) = undef THEN GOTO GetLine
PRINT I, "\n"
IPOS = 1
ELSE
GOTO LispCloseFile
END IF
END IF
BSD=BSD-1
RETURN

This will effectively fix 2 issues at once:

1a. Extra trailing empty lines in a LISP file; and

1b. Pressing Enter repeatedly with no input in the interactive mode which would currently render LISP inoperative and unresponsive to further commands once it would hit the first READ ERROR.

JRS

  • Guest
Re: Lisp in Basic
« Reply #232 on: August 08, 2014, 12:35:59 PM »
Quote
Will you please undo your repo sources of SBLisp so that I could use them for my future submissions here?

I don't understand what you mean by release the sources from Bitbucket. Do you undo my change to try and fix the extra lines issue?

Thanks for knocking this one off the list!


Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #233 on: August 08, 2014, 12:50:08 PM »
I didn't mean to "release". I used your own figure of speech as shown in the attached picture. Your previous fix for the extra lines can be reverted too because mine seems more compact and effectively addresses two issues at once.

[EDIT] !!! AHA !!! I got it! You meant "NOT" undone! I misunderstood it for "Not undone". Sorry, my bad! :D

.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #234 on: August 08, 2014, 12:55:45 PM »
OK then wait a minute while I'm downloading the sources. I'll update my code above and then you can copy-paste it directly. Just wait a little.

[UPD] Please hold on. Your repo version doesn't work as expected. My original SBLisp does while yours certainly doesn't. I need more time for merge compare them and I'll be posting the sources in a separate message as soon as I get them fixed.
« Last Edit: August 08, 2014, 01:27:42 PM by Mike Lobanovsky »

JRS

  • Guest
Re: Lisp in Basic
« Reply #235 on: August 08, 2014, 01:39:12 PM »
Sounds good Mike. BTW, you are able to download any of the uploads I made to Bitbucket. Just look at the history and pick the version you want. Bitbucker has a great compare feature.


JRS

  • Guest
Re: Lisp in Basic
« Reply #236 on: August 08, 2014, 02:47:10 PM »
Your fixes have been incorporated in the latest Bitbucket source. SBLisp also has command line script load support and mixed case filenames. Here are my quick tests. The first run had only one blank line at the end. The second had two blank lines and the third run shows running a script from the command line. (Mixed case filename)

Thanks again Mike. Great job!

Code: [Select]
jrs@laptop:~$ cd sb/sb22/sblisp
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
0](load 'Ave.scm)
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE
(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
0]   
0](quit)
Bye!
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
0](load 'Ave.scm)
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE
(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
0](quit)
Bye!
jrs@laptop:~/sb/sb22/sblisp$ scriba lisp.sb Ave.scm
Initializing Memory...
Initializing Lisp Environment...
LISP in BASIC v1.3 by Arthur Nunes-Harwitt
(define average
  (lambda (input)
    (print (/ (apply + input) (length input))) (newline)
  )
)
AVERAGE
(average (list 0 1 2 3 4 5 6 7 8 9))
4.500000
T
(quit)
Bye!
jrs@laptop:~/sb/sb22/sblisp$

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #237 on: August 08, 2014, 03:49:58 PM »
Why thanks John,

But I think you were just a little too fast to update it there.

Here's the latest version with all your extra blank line fixes nullified, filename DEBUG stuff removed (I presume you already have this running), and my fixes above added.

There's one more thing fixed. Once loaded and run from the file, the procedures should be runnable in an interactive mode too. FBSL does it without problems while SB runs a preloaded procedure for the first time but aborts on a second try with a bad file number error.

Try to (load 'Ave.scm) and run it then type (average (list 0 1 2 3 4 5 6 7 8 9)) (or (average '(0 1 2 3 4 5 6 7 8 9)) which is the same but shorter) and it will execute your command. But if you enter it again, it will execute it but will then break on SB's internal error. I can't trace the offending script line number (my scriba.exe won't show it).

So I have simply re-enabled SB's ON ERROR GOTO and HandleInternalError with a RESUME NEXT statement. That's a palliation because this effectively disables all own SB errors. My setup has neither a config file nor an include dir with errors.bas so I can't differentiate the error codes with error() and thus intercept and sink error &h14 only.

You can add your effort to our common cause by adding the errors.bas include to your setup and changing the existing error handler to

Code: [Select]
HandleInternalError:
  IF ERROR() = &H14 THEN
    ' Re-enable error trapping
    ON ERROR GOTO HandleInternalError
    ' Resume at next line
    RESUME NEXT
  END IF
  ' Resume at same line
  RESUME

just to test if it kills the bug as efficiently. Such a trap would suppress this particular bug only but would not ignore any other errors intrinsic to SB.

This error trap is impossible with my scriba.exe without the errors.bas include.

.
« Last Edit: August 08, 2014, 03:57:47 PM by Mike Lobanovsky »

JRS

  • Guest
Re: Lisp in Basic
« Reply #238 on: August 08, 2014, 04:01:18 PM »
I removed my blank line attempt before adding your fixes to the source. Please use the one on BitBucket as the MASTER to modify and use my formating rules.

Keywords - UPPER CASE
Labels / Functions / Subs - Mixed Case
Variables (ALL) - lower case

I think we  are good with the version I have posted.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #239 on: August 08, 2014, 04:17:46 PM »
John,

Where do you see but one single deviation from these formatting rules in my submission above?

Secondly, I will not work in such a pseudo-parallel mode on the SB sources. Please wait till I upload and announce that I'm trough whenever I take the SBList file down for work.

Didn't I ask you to hold on till I finish? I've done four major fixes instead of one planned.

I will not come back to the SBLisp sources until you assure me that the file I uploaded with the fix that I asked you to add is tested and uploaded to the repo as its final.

>:(