People,
I have questions about the below Spad program and its strange compilation:
------------------------------------------------- t.spad ------
OF ==> OutputForm
INT ==> Integer
CharList ==> List Character
Lexeme ==> String
LexList ==> List String
NLSTR ==> newline() :: String
NLOF ==> newline() :: OutputForm
)abbrev package DLIST1 DList1
DList1(T : Type) : with
lPair : (List T, List T) -> Product(List T, List T)
==
add
ListPair ==> Product(List T, List T)
lPair(xs : List T, ys : List T) : ListPair ==
construct(xs, ys) $ ListPair
)abbrev package HASHTAB1 HashTable1
HashTable1(Key : SetCategory, Val : SetCategory) : with
MbVal ==> Union(Val, "failed")
MbList ==> Union(List Val, "failed")
HashTab ==> HashTable(Key, Val, String)
searchMany : (List Key, HashTab) -> MbList
searchMany : (List Key, HashTab) -> List Val
==
add
searchMany(keys : List Key, tab : HashTab) : MbList ==
-- returns "failed" iff any of keys is not in tab
mbs := map(k +-> search(k, tab), keys)
any?(x +-> x case "failed", mbs) => "failed"
map(x +-> x :: Val, mbs) :: MbList
searchMany(keys : List Key, tab : HashTab) : List Val ==
-- breaks iff any of keys is not in tab
msg() : Void ==
oF := hconcat["searchMany ", keys :: OF, NLOF, " tab :"]
print(oF)$OF
mbL := searchMany(keys, tab) @ MbList
mbL case "failed" =>
(msg(); error "some key is not in the table.")
mbL :: List Val
)if false
parseINT ==> READ_-FROM_-STRING
)abbrev package DCHAR1 DChar1
DChar1() : with
mapChar : (String -> Character, List String) -> CharList
parenthesesF : () -> CharList
==
add
mapChar(f : String -> Character, xs : List String) : CharList ==
map(f, xs) $ ListFunctions2(String, Character)
parenthesesF() : CharList ==
mapChar(char, ["(", ")", "[", "]", "{", "}"])
)endif
--------------------------------------------------------------
1.
FriCAS-1.1.6 (SBCL 1.0.55) reports
------------------------------------------------------------
...
DList1 will be automatically loaded when needed from
/home/mechvel/haxiom/fromA-aim/DLIST1.NRLIB/DLIST1
HASHTAB1 abbreviates package HashTable1
******** Boot Syntax Error detected ********
The prior line was:
21> HashTable1(Key : SetCategory, Val : SetCategory) : with
The current line is:
23> (MbVal ==> Union(Val, "failed");
^
First currently preparsed lines are:
24> MbList ==> Union(List Val, "failed");
25> HashTab ==> HashTable(Key, Val, String);
27> searchMany : (List Key, HashTab) -> MbList;
28> searchMany : (List Key, HashTab) -> List Val)
29> ==
The number of valid tokens is 1.
The prior token was #S(TOKEN :SYMBOL |MbVal| :TYPE IDENTIFIER :NONBLANK T)
The current token is #S(TOKEN :SYMBOL ==> :TYPE KEYWORD :NONBLANK NIL)
******** Boot Syntax Error detected ********
------------------------------------------------------------
After un-commenting the trailing fragment of
)if false
...
)endif
the program is compiled! What is the difference?
2.
In the above package HashTable1(Key: SetCategory, Val: SetCategory) ...
I write
MbVal ==> Union(Val, "failed")
MbList ==> Union(List Val, "failed")
HashTab ==> HashTable(Key, Val, String)
searchMany : (List Key, HashTab) -> MbList
...
==
add
...
-- with this precise indentation. Because I want to
(a) make these 3 macros local in the package: not visible from outside
(because Key and Val are local),
(b) to use these macros in the signature of searchMany -- before the
implementation part.
What may be a correct syntax to arrange this?
3.
Does the code for searchMany look natural?
Can it be replaced with a standard library thing?
Thanks,
------
Sergei
[email protected]
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.