Author Topic: Lisp in Basic  (Read 208028 times)

0 Members and 2 Guests are viewing this topic.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #1005 on: April 17, 2015, 08:41:55 PM »
Parsers? In interpretative languages?!  :o

JRS

  • Guest
Re: Lisp in Basic
« Reply #1006 on: April 17, 2015, 09:12:50 PM »
Here is a brute force XML parser in Script BASIC.

xmlparse.sb
Code: Script BASIC
  1. IMPORT t.bas
  2.  
  3. xml = t::LoadString("sample.xml")
  4.  
  5. SPLITA xml BY ">" TO a
  6.  
  7. FOR x = 0 TO UBOUND(a)
  8.   IF LEFT(TRIM(a[x]),1) = "<" THEN GOTO IT
  9.   p = INSTR(a[x],"<")
  10.   PRINT MID(a[x],p+2) & " = " & LEFT(a[x],p-1),"\n"
  11. IT:
  12. NEXT
  13.  


Example XML residential listing
Code: XML
  1. <Listings xmlns="http://www.nwmls.com/Schemas/Standard/StandardXML1_1.xsd">
  2.         <Residential>
  3.                 <LN>62981</LN>
  4.                 <PTYP>RESI</PTYP>
  5.                 <LAG>27022</LAG>
  6.                 <ST>CT</ST>
  7.                 <LP>599950.00</LP>
  8.                 <SP>0.00</SP>
  9.                 <OLP>599950.00</OLP>
  10.                 <HSN>4538</HSN>
  11.                 <DRP/>
  12.                 <STR>23rd</STR>
  13.                 <SSUF>Ave</SSUF>
  14.                 <DRS>SW</DRS>
  15.                 <UNT/>
  16.                 <CIT>Seattle</CIT>
  17.                 <STA>WA</STA>
  18.                 <ZIP>98126</ZIP>
  19.                 <PL4/>
  20.                 <BR>5.00</BR>
  21.                 <BTH>3.50</BTH>
  22.                 <ASF>3650</ASF>
  23.                 <LSF>4800</LSF>
  24.                 <UD>2010-04-24 14:59:25</UD>
  25.                 <AR>140</AR>
  26.                 <DSRNUM>7215</DSRNUM>
  27.                 <LDR>2010-04-24 00:00:00</LDR>
  28.                 <LD>2010-04-24 00:00:00</LD>
  29.                 <CLO>1800-01-01 00:00:00</CLO>
  30.                 <YBT>2010</YBT>
  31.                 <LO>1401</LO>
  32.                 <TAX>1773600264</TAX>
  33.                 <MAP>594</MAP>
  34.                 <GRDX>G</GRDX>
  35.                 <GRDY>4</GRDY>
  36.                 <SAG>0</SAG>
  37.                 <SO>0</SO>
  38.                 <NIA>Y</NIA>
  39.                 <MR>Third of three New Contemporary Homes w/fantastic open floor plans and great level and fenced backyards.These homes have wonderful tall ceilings,designer paint,fully wrapped windows,solid core/glass int doors and top of the line strand Bamboo flrs.The kitchen is an entertainers dream w/an enormous open eating bar,honed granite counters,custom wood cabinets,top of the line stainless steel appls and french doors to the ent backyard. Quality and Designer features from top to Bottom, a must see!!</MR>
  40.                 <LONG>-122.362210</LONG>
  41.                 <LAT>47.561975</LAT>
  42.                 <PDR>1800-01-01 00:00:00</PDR>
  43.                 <CLA>0</CLA>
  44.                 <SHOADR>Y</SHOADR>
  45.                 <DD>From Delridge Way head east on Oregon which becomes 23rd.</DD>
  46.                 <AVDT>1800-01-01 00:00:00</AVDT>
  47.                 <INDT>1800-01-01 00:00:00</INDT>
  48.                 <COU>King</COU>
  49.                 <CDOM>0</CDOM>
  50.                 <CTDT>2010-04-24 00:00:00</CTDT>
  51.                 <SCA>0</SCA>
  52.                 <SCO>0</SCO>
  53.                 <VIRT/>
  54.                 <SD>SEA</SD>
  55.                 <SDT>2010-04-24 00:00:00</SDT>
  56.                 <FIN/>
  57.                 <MAPBOOK>THOM</MAPBOOK>
  58.                 <DSR>Pigeon Point</DSR>
  59.                 <QBT>0</QBT>
  60.                 <LSZS/>
  61.                 <HSNA/>
  62.                 <COLO>0</COLO>
  63.                 <PIC>1</PIC>
  64.                 <ADU/>
  65.                 <ARC>K</ARC>
  66.                 <BDC/>
  67.                 <BDL>2</BDL>
  68.                 <BDM>0</BDM>
  69.                 <BDU>3</BDU>
  70.                 <BLD>JDR Development Inc</BLD>
  71.                 <BLK>14</BLK>
  72.                 <BRM/>
  73.                 <BUS>Y</BUS>
  74.                 <DNO>L</DNO>
  75.                 <DRM>M</DRM>
  76.                 <EFR/>
  77.                 <EL/>
  78.                 <ENT>M</ENT>
  79.                 <F17>A</F17>
  80.                 <FAM>M</FAM>
  81.                 <FBG>0</FBG>
  82.                 <FBL>1</FBL>
  83.                 <FBM>0</FBM>
  84.                 <FBT>3</FBT>
  85.                 <FBU>2</FBU>
  86.                 <FP>1</FP>
  87.                 <FPL>0</FPL>
  88.                 <FPM>1</FPM>
  89.                 <FPU>0</FPU>
  90.                 <GAR>2</GAR>
  91.                 <HBG>0</HBG>
  92.                 <HBL>0</HBL>
  93.                 <HBM>1</HBM>
  94.                 <HBT>1</HBT>
  95.                 <HBU>0</HBU>
  96.                 <HOD>0</HOD>
  97.                 <JH/>
  98.                 <KES>M</KES>
  99.                 <KIT/>
  100.                 <LRM>M</LRM>
  101.                 <LSD/>
  102.                 <LSZ/>
  103.                 <LT>16</LT>
  104.                 <MBD>U</MBD>
  105.                 <MHM/>
  106.                 <MHN/>
  107.                 <MHS/>
  108.                 <MOR>0</MOR>
  109.                 <NC>U</NC>
  110.                 <POC>SEA</POC>
  111.                 <POL/>
  112.                 <PRJ>Cottage Grove # 3</PRJ>
  113.                 <PTO>Y</PTO>
  114.                 <TQBT>0</TQBT>
  115.                 <RRM>L</RRM>
  116.                 <SAP>0</SAP>
  117.                 <SFF>0</SFF>
  118.                 <SFS>Per Builder Plans</SFS>
  119.                 <SFU>0</SFU>
  120.                 <SH/>
  121.                 <SML>Y</SML>
  122.                 <SNR>N</SNR>
  123.                 <STY>18</STY>
  124.                 <SWC>SEA</SWC>
  125.                 <TBG>0</TBG>
  126.                 <TBL>0</TBL>
  127.                 <TBM>0</TBM>
  128.                 <TBU>0</TBU>
  129.                 <TX>0</TX>
  130.                 <TXY>0</TXY>
  131.                 <UTR>U</UTR>
  132.                 <WAC>SEA</WAC>
  133.                 <WFG/>
  134.                 <WHT/>
  135.                 <APS>A|D|E|F|G</APS>
  136.                 <BDI>E</BDI>
  137.                 <BSM>A|B</BSM>
  138.                 <ENS>B</ENS>
  139.                 <EXT>J|E</EXT>
  140.                 <FEA>A|D|F|G|J|M|P|T</FEA>
  141.                 <FLS>J|A|G</FLS>
  142.                 <FND>E|F</FND>
  143.                 <GR>C</GR>
  144.                 <HTC>B</HTC>
  145.                 <LDE>H|J</LDE>
  146.                 <LTV>E|F</LTV>
  147.                 <POS>A</POS>
  148.                 <RF>C</RF>
  149.                 <SIT>G|H|M|Y|N</SIT>
  150.                 <SWR>A</SWR>
  151.                 <TRM>B|C</TRM>
  152.                 <VEW>D|L</VEW>
  153.                 <WAS>D</WAS>
  154.                 <WFT/>
  155.                 <BUSR/>
  156.                 <CMFE/>
  157.                 <ECRT/>
  158.                 <ZJD>A</ZJD>
  159.                 <ZNC>SF 5000</ZNC>
  160.                 <ProhibitBLOG>Y</ProhibitBLOG>
  161.                 <AllowAVM>Y</AllowAVM>
  162.                 <PARQ>N</PARQ>
  163.                 <BREO>N</BREO>
  164.         </Residential>
  165. </Listings>
  166.  

Results

jrs@laptop:~/sb/sb22/test$ time scriba xmlparse.sb
LN = 62981
PTYP = RESI
LAG = 27022
ST = CT
LP = 599950.00
SP = 0.00
OLP = 599950.00
HSN = 4538
STR = 23rd
SSUF = Ave
DRS = SW
CIT = Seattle
STA = WA
ZIP = 98126
BR = 5.00
BTH = 3.50
ASF = 3650
LSF = 4800
UD = 2010-04-24 14:59:25
AR = 140
DSRNUM = 7215
LDR = 2010-04-24 00:00:00
LD = 2010-04-24 00:00:00
CLO = 1800-01-01 00:00:00
YBT = 2010
LO = 1401
TAX = 1773600264
MAP = 594
GRDX = G
GRDY = 4
SAG = 0
SO = 0
NIA = Y
MR = Third of three New Contemporary Homes w/fantastic open floor plans and great level and fenced backyards.These homes have wonderful tall ceilings,designer paint,fully wrapped windows,solid core/glass int doors and top of the line strand Bamboo flrs.The kitchen is an entertainers dream w/an enormous open eating bar,honed granite counters,custom wood cabinets,top of the line stainless steel appls and french doors to the ent backyard. Quality and Designer features from top to Bottom, a must see!!
LONG = -122.362210
LAT = 47.561975
PDR = 1800-01-01 00:00:00
CLA = 0
SHOADR = Y
DD = From Delridge Way head east on Oregon which becomes 23rd.
AVDT = 1800-01-01 00:00:00
INDT = 1800-01-01 00:00:00
COU = King
CDOM = 0
CTDT = 2010-04-24 00:00:00
SCA = 0
SCO = 0
SD = SEA
SDT = 2010-04-24 00:00:00
MAPBOOK = THOM
DSR = Pigeon Point
QBT = 0
COLO = 0
PIC = 1
ARC = K
BDL = 2
BDM = 0
BDU = 3
BLD = JDR Development Inc
BLK = 14
BUS = Y
DNO = L
DRM = M
ENT = M
F17 = A
FAM = M
FBG = 0
FBL = 1
FBM = 0
FBT = 3
FBU = 2
FP = 1
FPL = 0
FPM = 1
FPU = 0
GAR = 2
HBG = 0
HBL = 0
HBM = 1
HBT = 1
HBU = 0
HOD = 0
KES = M
LRM = M
LT = 16
MBD = U
MOR = 0
NC = U
POC = SEA
PRJ = Cottage Grove # 3
PTO = Y
TQBT = 0
RRM = L
SAP = 0
SFF = 0
SFS = Per Builder Plans
SFU = 0
SML = Y
SNR = N
STY = 18
SWC = SEA
TBG = 0
TBL = 0
TBM = 0
TBU = 0
TX = 0
TXY = 0
UTR = U
WAC = SEA
APS = A|D|E|F|G
BDI = E
BSM = A|B
ENS = B
EXT = J|E
FEA = A|D|F|G|J|M|P|T
FLS = J|A|G
FND = E|F
GR = C
HTC = B
LDE = H|J
LTV = E|F
POS = A
RF = C
SIT = G|H|M|Y|N
SWR = A
TRM = B|C
VEW = D|L
WAS = D
ZJD = A
ZNC = SF 5000
ProhibitBLOG = Y
AllowAVM = Y
PARQ = N
BREO = N

 =

real   0m0.038s
user   0m0.005s
sys   0m0.002s
jrs@laptop:~/sb/sb22/test$
« Last Edit: April 17, 2015, 09:20:34 PM by John »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #1007 on: April 17, 2015, 09:16:59 PM »
Oh, I see. Such parsers...

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #1008 on: April 18, 2015, 07:02:15 AM »
(This code should also run in OxyScheme!)

It runs but it doesn't produce the expected results. There must be still some bugs somewhere in OxyScheme...  :(

JRS

  • Guest
Re: Lisp in Basic
« Reply #1009 on: April 18, 2015, 07:07:13 AM »
(This code should also run in OxyScheme!)

It runs but it doesn't produce the expected results. There must be still some bugs somewhere in OxyScheme...  :(

I was surprised how fast your TinyScheme version was. PHP was also a surprise.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #1010 on: April 18, 2015, 08:24:35 AM »
Hi John,

This is the executable that I've compiled using MS VC6 with the /O2 (favor fast code) switch. It is only 108KB large including the DL interface. Actually, once timeit tinyscheme.exe primes2 is run several times and all data is in the disk cache, the script gets executed substantially faster. Note that timeit tinyscheme.exe own exec time (init.scm included) is as low as 6 msec only:

C:\tinyscheme>timeit tinyscheme.exe primes2
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
Uptime 0 min :: 0 sec :: 92.245 msec

JRS

  • Guest
Re: Lisp in Basic
« Reply #1011 on: April 18, 2015, 09:27:26 AM »
Here is my TinyScheme as a 64 bit library and called from Script BASIC raw execution speed.

Code: Script BASIC
  1. IMPORT ts.inc
  2.  
  3. sc = TS_New()
  4. TS_Cmd sc, "(load \"init.scm\")"
  5. TS_Close sc
  6.  


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

real   0m0.140s
user   0m0.007s
sys   0m0.008s
jrs@laptop:~/sb/sb22/TS$


Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #1012 on: April 18, 2015, 11:15:44 AM »
John,

AFAIK TinyScheme loads its init.scm automatically at app start and throws a Could not open file init.scm warning if the file is missing. If it is then TinyScheme will work but its functionality and compliance with R5RS will be severely compromised because init.scm is effectively an R5RS runtime library.

Are you sure you can't confine it to just letting it start all by itself? Probably "(load \"init.scm\")" is redundant? TinyScheme wouldn't complain about loading a file more than once... :-\

JRS

  • Guest
Re: Lisp in Basic
« Reply #1013 on: April 18, 2015, 11:22:16 AM »
I'm pretty sure if your calling TinyScheme as a library, loading init.scm is a manual process. This is what is reported running your Prime Number example without loading the init.scm first.


jrs@laptop:~/sb/sb22/TS$ scriba tspnmike.sb
Error: eval: unbound variable: do
jrs@laptop:~/sb/sb22/TS$



Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #1014 on: April 18, 2015, 11:45:42 AM »
That's correct. As seen in the sources, init.scm is loaded automatically in the main() function of an executable but not in a library. Thanks for trying it out anyway.

JRS

  • Guest
Re: Lisp in Basic
« Reply #1015 on: April 18, 2015, 01:10:31 PM »
I'm happy with the TinyScheme and Perl extension module interfaces so far. It's a nice addition to Script BASIC. I hope it attracts more users.

I thought I would try to do a time test without loading the init.scm (a fairly extensive library in text) but it segment faulted. I added a simple (quit) and it worked.

I have to say that extending the TinyScheme language with the init.scm is a easy and painless way to go. It also serves as a learning reference to some of the more advanced features of the language. I hope to follow Mike's lead and become more proficient in Scheme.

Code: Script BASIC
  1. IMPORT ts.inc
  2.  
  3. sc = TS_New()
  4. TS_Cmd sc, "(quit)"
  5. TS_Close sc
  6.  


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

real   0m0.003s
user   0m0.002s
sys   0m0.000s
jrs@laptop:~/sb/sb22/TS$


« Last Edit: April 18, 2015, 05:53:21 PM by John »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #1016 on: April 18, 2015, 05:52:36 PM »
Below is a typical reading I'm getting when running the "raw" script with a sole (quit) inside. But this reading includes the time it takes TinyScheme to load its init.scm script before it loads the "raw" script and quits immediately.

(TimeIt is an FBSL console executable, and FBSL uses a console that's somewhat wider than the system default.)

.

JRS

  • Guest
Re: Lisp in Basic
« Reply #1017 on: April 18, 2015, 05:57:08 PM »
@Mike - Is TinyScheme usable without the init.scm extension library? Do you feel it's worth making an optional (load) requirement rather than forcing it on you as a default?

Attached is a millisecond to second conversion to help translate the different times being shown.

.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #1018 on: April 18, 2015, 06:12:24 PM »
I would say no, John. As per R5RS, the Scheme syntax is divided more or less evenly between standard and library keywords and procedures. Standard syntax is implemented in the binary while the library is written in Scheme proper and is to the language what system header files with their macros are to C. For example, there are no iteration constructs in Scheme but the library (init.scm in this case) defines the corresponding macros for general-purpose Scheme scripts to be usable and executable in TinyScheme.

Neither Rob's nor my script would be runnable without init.scm which, among many other things, also defines the (do) iteration macro.

JRS

  • Guest
Re: Lisp in Basic
« Reply #1019 on: April 18, 2015, 06:37:45 PM »
I'm thinking that a Script BASIC batch command processor could be built as a compiled SB to C script that uses SB, Perl and TinyScheme (text) scripts as user code. SB supports redirection on the command line as well as standard error. I never could get my arms around bash and other batch languages to do anything beyond simple tasks.  :-\

What would be cool is to do the above but do the processing on the Script BASIC sbhttpd multi-threaded application server.  8)
« Last Edit: April 18, 2015, 06:55:54 PM by John »