People,
can you, please, answer the following beginner questions about the Spad
language and library?
escape() Instead of '`' it shows the underscore: '_'
-------- (in fricas-1.1.5).
Is this all right?
Defining a constant
-------------------
I define parentheses : () -> Set Character
parentheses() == ...
in a package.
I need to apply it not as, for example, ps := f parentheses()
but as ps := f parentheses,
where parentheses : Set Caracter.
But this latter does work. How to arrange this?
I tried parentheses : Set Character
parentheses := ...
...
ps := parentheses,
but it does not work.
Using type (domain) synomym
---------------------------
I tried to declare in my package
... package ... with
Lexeme : SetCategory
spanStr : (Character -> Boolean, String) -> Product(Lexeme, String)
==
add
Lexeme : SetCategory := String
...
< a code using the Lexeme type as String >
and had difficulties. Finally I replaced Lexeme with String.
What is your advice on this?
Membership to a fixed finite set
--------------------------------
I put
delimiters() : Set Character ==
construct( map(char, ["(", ")", ..., ",", ":", ...]) )
:: Set Character
-- a set of about 30 characters
delimiter? x == member?(x, delimiters())
Is this a reasonable way to define this predicate?
Is it computed fast -- by the binary search?
When delimiter? is applied repeatedly in different places in a
program, does this lead to repeated build of the set delimiters() ?
May be, put
delims := delimiters()
and then, use delims in the scope?
Generalization of String and List
---------------------------------
I define
dropWhileInStr(p: Character -> Bool, xs: String) : String ==
empty? xs => ""
p first(xs) => dropWhileInStr(p, delete(xs, 1))
xs
for dropping first letters from xs which satisfy a predicate p.
It this a reasonable code?
I would like to generalize it for working uniformly for String and
List T, something like
package Foo(T : Type, Agg : Aggregate T ??)
...
add
dropWhile(p: T -> Bool, xs : Agg) : Agg ==
empty? xs => xs
...
What might be the code?
Function composition
--------------------
I write map(x +-> not p(x), xs) for xs :: List T.
But it is nicer to write
map((not . p), xs),
where `.' is composition of functions
(in Haskell, it is simpler: map (not . p) xs ).
What the Spad library has to replace this `.' ?
Thank you in advance for explanation,
------
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.