spad
)abbrev package SSPM SuperSimplePatternMatcher
++ Author: Kurt Pagani
++ Date Created: Mon Feb 06 18:56:20 CET 2017
++ License: BSD
++ References:
++ www.cs.northwestern.edu/academics/courses/325/programs/pat-match.lisp
++ Description:
++ www.cs.northwestern.edu/academics/courses/325/readings/pat-match.php
++
SuperSimplePatternMatcher(X) : Exports == Implementation where
X: Join(ConvertibleTo InputForm, ExpressionSpace)
IF ==> InputForm
SEXP ==> SExpression
Exports == with
cons : (IF,IF) -> IF
++ Cons
varp : IF -> Boolean
++
match : (IF,IF,IF) -> IF
Implementation == IF add
null:IF:=convert([])$IF
cons(a:IF,b:IF):IF ==
s:SExpression:=CONS(a,b)$Lisp
convert(s)$IF
varp(a:IF):Boolean ==
not symbol? a => false
s:String:=unparse(a)$IF
test(s.(#s)::String="?")
addBinding(var:IF,input:IF,blists:IF):IF ==
convert [cons(cons(var,input),car blists)]
getBinding(var:IF,bindings:IF):IF ==
s:SExpression:=ASSOC(var,bindings)$Lisp
convert(s)$IF
extendBindings(var:IF,input:IF,blists:IF):IF ==
binding:=getBinding(var,car blists)
null? binding => addBinding(var,input,blists)
cdr(binding)=input => blists
null
matchVariable(var:IF,input:IF,blists:IF):IF ==
null? blists => null
null? cdr blists => extendBindings(var,input,blists)
bs:List IF:=destruct blists
convert [extendBindings(var,input,convert [b]) for b in bs]
match(pat:IF,input:IF,blists:IF):IF ==
varp pat => matchVariable(pat,input,blists)
pat=input => blists
atom? pat or atom? input => null
match(cdr pat,cdr input,match(car pat,car input, convert [blists]))
spad
Compiling FriCAS source code from file
/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/14984357514337006-25px001.spad
using old system compiler.
SSPM abbreviates package SuperSimplePatternMatcher
------------------------------------------------------------------------
initializing NRLIB SSPM for SuperSimplePatternMatcher
compiling into NRLIB SSPM
****** Domain: X already in scope
compiling exported cons : (InputForm,InputForm) -> InputForm
Time: 0.01 SEC.
compiling exported varp : InputForm -> Boolean
Time: 0.02 SEC.
compiling local addBinding : (InputForm,InputForm,InputForm) -> InputForm
Time: 0.01 SEC.
compiling local getBinding : (InputForm,InputForm) -> InputForm
Time: 0 SEC.
compiling local extendBindings : (InputForm,InputForm,InputForm) -> InputForm
Time: 0 SEC.
compiling local matchVariable : (InputForm,InputForm,InputForm) -> InputForm
Time: 0.01 SEC.
compiling exported match : (InputForm,InputForm,InputForm) -> InputForm
Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |SuperSimplePatternMatcher| REDEFINED
;;; *** |SuperSimplePatternMatcher| REDEFINED
Time: 0 SEC.
Cumulative Statistics for Constructor SuperSimplePatternMatcher
Time: 0.05 seconds
--------------non extending category----------------------
.. SuperSimplePatternMatcher(#1) of cat
(CATEGORY |package|
(SIGNATURE |cons| ((|InputForm|) (|InputForm|) (|InputForm|)))
(SIGNATURE |varp| ((|Boolean|) (|InputForm|)))
(SIGNATURE |match| ((|InputForm|) (|InputForm|) (|InputForm|) (|InputForm|)))) has no
(|SExpressionCategory| (|String|) (|Symbol|) (|Integer|) (|DoubleFloat|)) finalizing NRLIB SSPM
Processing SuperSimplePatternMatcher for Browser database:
--------constructor---------
--------(cons ((InputForm) (InputForm) (InputForm)))---------
--------(varp ((Boolean) (InputForm)))---------
--->-->SuperSimplePatternMatcher((match ((InputForm) (InputForm) (InputForm) (InputForm)))): Not documented!!!!
; compiling file "/var/aw/var/LatexWiki/SSPM.NRLIB/SSPM.lsp" (written 16 JUL 2018 08:53:02 PM):
; /var/aw/var/LatexWiki/SSPM.NRLIB/SSPM.fasl written
; compilation finished in 0:00:00.035
------------------------------------------------------------------------
SuperSimplePatternMatcher is now explicitly exposed in frame initial
SuperSimplePatternMatcher will be automatically loaded when needed
from /var/aw/var/LatexWiki/SSPM.NRLIB/SSPM
Test flavours
fricas
)set break resume
IF==>InputForm
Type: Void
fricas
X ==> Expression Integer
Type: Void
fricas
PM==>SSPM(X)
Type: Void
fricas
null:=convert([])$IF
fricas
p:=convert([a,x?,b]::List IF)
fricas
q:=convert([a,j,b]::List IF)
fricas
m1:=match(p,q,null)$PM
fricas
l1:=convert([b,y?]::List IF)
fricas
l2:=convert([b,jack]::List IF)
fricas
p:=convert([a,x?,l1]::List IF)
fricas
q:=convert([a,j,l2]::List IF)
fricas
m2:=match(p,q,null)$PM