I discovered - quite by accident - that I could use the modules I needed, even without compiling in FFI: just as Lutz points out.
I'll experiment further when time allows, and report back here.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
(define-macro (iparse _sent)
(setq parses nul)
(setq stack nul)
(setq jumpflag nil)
(setq sentence _sent)
(setq state 's)
(setq star (first sentence))
(atn state sentence)
(and parses true ) )
(define (pushlex)
(push (list star sentence) *lexenvironment) )
(define (poplex)
(map set '(star sentence) (pop *lexenvironment)) )
(define (atn state sentence)
(let (arcs result (savealist alist))
(cond ((null? (setq arcs (first (rest (assoc state network)))))
nil ))
(catch
(while true
(cond ((setq result (evalarc (first arcs) alist))
(throw result))
((setq arcs (rest arcs)) (setq alist savealist))
(true (throw nil)))))))
(define (evalarc arc alist)
(let ((type (arc 0))
(head (arc 1))
(test (arc 2))
(actions (3 arc)))
(cond ((null? (eval test)) nil)
((= type 'pop) (evall actions)
(popatn (eval head)))
((null? star) nil)
((= type 'wrd) (and (= star head)
(evall actions)))
(else (println "bad arc: " arc) nil) )))
(define (evall lis)
(when lis
(eval (cons 'begin lis)) ))
(define-macro (to _state)
; effect transition to state _state.
; advance input unless jumpflag is set
; fail if there are no more words in input
(cond (jumpflag (setq jumpflag nil)
(pushlex)
(setq star (first sentence))
(cond ((atn _state sentence) )
(else (poplex) nil) ))
(sentence (pushlex)
(setq star (first (rest sentence))) ; could we not reverse/simplify these 2 lines?
(setq sentence (rest sentence))
(cond ((atn _state sentence) )
(else (poplex) nil) ))
(else (println " blocked : out of words")
nil )))
(define (popatn value)
; pops from a sub-network
(cond (stack ;;; so from earlier push
(let ((save star)
(savestack stack)
(savealist alist)
(continuation (rest (first stack))) )
(setq alist (append liftlist (first (first stack))))
(setq stack (rest stack))
(setq star value)
(setq sendlist nul)
(setq jumpflag true)
(cond ((evall continuation) )
(else (setq star save)
(setq stack savestack)
(setq alist savealist)
nil ) )))
(sentence (println "pop blocked - unused words")
nil)
(holdlist (println "pop blocked - non-empty hold list")
nil)
(else ;;; final pop
(setq parses (cons value parses))
true ) ))
(define (pushatn state actions)
;; STUB
)
(setq network '( ;; GRAMMAR 0
(s ( (wrd grasp true (to s2)) ))
(s2 ( (pop 'success true (println 'OK)) ))
))
(set 'dictionary '( ;; LEXICON 0
(grasp v () (trans1) )
(grasp n () (reach) )
))
(define (dict-entry _star _head) ; return entry if present, or nil
(find-all (list _star _head '*) dictionary) )
;; Needs to be like this because we are finding more than one word with
;; same value, but different category, so will be able to add semantics
(setq nul '())
(constant 'else true)
(setq alist nul
*lexenvironment nul)
(load "odd.pl")
(debug (iparse (grasp)))
(load "odd.pl")
(iparse (grasp))
(begin (setq z (read-line))(println "parse z= " (parse z)))
hey this is great
parse z= ("(" "begin" "(" "setq" "z" "(" "read-line" ")" ")" "(" "println" "parse z= " "("
"parse" "z" ")" ")" ")")
("(" "begin" "(" "setq" "z" "(" "read-line" ")" ")" "(" "println" "parse z= " "("
"parse" "z" ")" ")" ")")
> nil
nil
nil
nil