zak
01-11-2010, 12:10
newlisp www.newlisp.org (http://www.newlisp.org) is a script language and a small size core engine with many many modules addons , can display graphics , opengl, tk and much more, and can be called by other programs like powerbasic and vb , the following code is an adaptation of a vb6 program to load "newlisp.dll" and passing a string which contains the lisp program then reading the return result from memory.
the vb6 program can be found here near the end of this page:
http://www.newlisp.org/index.cgi?Code_Contributions
the newlisp.dll can be downloaded from here
https://sites.google.com/site/perlopengl/newlisp.rar , or install the newlisp , the dll in its folder.
the program we will pass to newlisp is a factorial program in fac.txt file in the same thinbasic code.
(define (fac n)
(if (= n 0)
1
(* n (fac (- n 1)))))
(fac 3)
you can also write lisp code in a multiline TextBox in a GUI mode.
you will notice that the program return a listing of the code before printing the results of (fac 3) and (fac 10), i do not yet how how to stop this listing. i may ask newlisp forum.
thinbasic program:
Uses "console", "File"
Declare Function dllNewlispEval Lib "newlisp.dll" Alias "newlispEvalStr" (ByVal LExpr As String) As Long
Declare Function LoadLibrary Lib "KERNEL32.DLL" Alias "LoadLibraryA" (ByVal s As String) As Long
Declare Function FreeLibrary Lib "KERNEL32.DLL" Alias "FreeLibrary" (ByVal hLibModule As DWord) As Long
Declare Function lstrLen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long
Declare Function lstrCpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Global NewlispHandle As Long
Global outText As String
LoadNewLISP() 'loading the newlisp library
Dim inText As String
inText = FILE_Load("fac.txt")
outText = newlispEval(inText)
PrintL outText
inText = "(fac 10)"
outText = newlispEval(inText)
PrintL outText
UnloadNewLISP()
WAITKEY
Sub LoadNewLISP()
Dim mylib As String
Dim hinst As Long
mylib = "newlisp.dll"
NewlispHandle = LoadLibrary(mylib)
If NewlispHandle = 0 Then
MsgBox "NewLISP cannot be found"
End
End If
End Sub
Sub UnloadNewLISP()
FreeLibrary NewlispHandle
End Sub
Function newlispEval(LispExpression As String) As String
Dim stringlen As Integer
Dim ResHandle As Long
Dim Result As String
ResHandle = dllNewlispEval(LispExpression)
stringlen = lstrLen(ResHandle)
Result = Peek$(ResHandle, stringlen)
newlispEval = Result
End Function
links:
http://community.thinbasic.com/index.php?topic=3384.0
http://community.thinbasic.com/index.php?topic=3441.0
http://newlispfanclub.alh.net/forum/
http://newlisp.nfshost.com/benchmarks/
http://en.wikibooks.org/wiki/Introduction_to_newLISP
http://www.rhinocerus.net/forum/lang-lisp/427132-newlisp-simple-terse-well-documented.html
the vb6 program can be found here near the end of this page:
http://www.newlisp.org/index.cgi?Code_Contributions
the newlisp.dll can be downloaded from here
https://sites.google.com/site/perlopengl/newlisp.rar , or install the newlisp , the dll in its folder.
the program we will pass to newlisp is a factorial program in fac.txt file in the same thinbasic code.
(define (fac n)
(if (= n 0)
1
(* n (fac (- n 1)))))
(fac 3)
you can also write lisp code in a multiline TextBox in a GUI mode.
you will notice that the program return a listing of the code before printing the results of (fac 3) and (fac 10), i do not yet how how to stop this listing. i may ask newlisp forum.
thinbasic program:
Uses "console", "File"
Declare Function dllNewlispEval Lib "newlisp.dll" Alias "newlispEvalStr" (ByVal LExpr As String) As Long
Declare Function LoadLibrary Lib "KERNEL32.DLL" Alias "LoadLibraryA" (ByVal s As String) As Long
Declare Function FreeLibrary Lib "KERNEL32.DLL" Alias "FreeLibrary" (ByVal hLibModule As DWord) As Long
Declare Function lstrLen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long
Declare Function lstrCpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Global NewlispHandle As Long
Global outText As String
LoadNewLISP() 'loading the newlisp library
Dim inText As String
inText = FILE_Load("fac.txt")
outText = newlispEval(inText)
PrintL outText
inText = "(fac 10)"
outText = newlispEval(inText)
PrintL outText
UnloadNewLISP()
WAITKEY
Sub LoadNewLISP()
Dim mylib As String
Dim hinst As Long
mylib = "newlisp.dll"
NewlispHandle = LoadLibrary(mylib)
If NewlispHandle = 0 Then
MsgBox "NewLISP cannot be found"
End
End If
End Sub
Sub UnloadNewLISP()
FreeLibrary NewlispHandle
End Sub
Function newlispEval(LispExpression As String) As String
Dim stringlen As Integer
Dim ResHandle As Long
Dim Result As String
ResHandle = dllNewlispEval(LispExpression)
stringlen = lstrLen(ResHandle)
Result = Peek$(ResHandle, stringlen)
newlispEval = Result
End Function
links:
http://community.thinbasic.com/index.php?topic=3384.0
http://community.thinbasic.com/index.php?topic=3441.0
http://newlispfanclub.alh.net/forum/
http://newlisp.nfshost.com/benchmarks/
http://en.wikibooks.org/wiki/Introduction_to_newLISP
http://www.rhinocerus.net/forum/lang-lisp/427132-newlisp-simple-terse-well-documented.html