On Sat, Feb 04, 2012 at 10:45:54PM +0100, Waldek Hebisch wrote:
> Serge D. Mechveliani wrote:
> >
> > But where to set "import", in what place of the Spad code for a package,
> > or a category etc.? I do not see examples.
>
> grep -w import src/algebra/*.spad.*
Thank you.
For example, view3D.spad.pamphlet: import Set(PositiveInteger)
Does this means to substitute PositiveInteger for the type parameter T
in the package Set and to import the result -- ?
I would like a thing like this:
import Foo(Character)(foo, TT)
-- to import (after substitution) only the foo function and the TT type.
Only the syntax is, probably wrong.
> > What is the meaning of import?
> > If f is not imported from a package Foo, is can be used by f$Foo,
> > is this so?
> > If f is imported from Foo, can it be used as `f' ?
>
> More or less. f$Foo take f from Foo even if other f exist.
> if there are several f-s in scope (remember, Spad allows
> heavy overloading) then Spad compiler tries them in sequence,
> and takes the first one which make expression type correct.
> So if you have too many f-s Spad compiler may pick wrong
> one. Let me add that Spad compiler typecheck expressions
> separately, so the typical outcome is type error in later
> expression. So if f is heavily overloaded it may be wise
> to use f$Foo form to be sure that you get correct f.
>
> BTW: If you get type errors which make no sense the first
> thing to do is to add $Foo qualifications to calls.
> Sometimes after that error will go away, in most other
> cases you will get sensible error message.
I see. These features are somehat similar to Haskell.
But here is a small example:
the below package DChar1 uses dropWhile and span of the package
DList1.
For dropWhile, the comiler insists on adding $ DList1(Character)
(otherwise reports of a certain error).
And is accepts `span' without `import' and without package calling.
I searched "span" in Browse - Operations, and it is not found, so,
probably, it is not of the library.
What may this mean?
------------------------------------- Foo.spad ----------------------
)abbrev package DLIST1 DList1
DList1(T : Type) : with
lPair : (List T, List T) -> Product(List T, List T)
dropWhile : (T -> Boolean, List T) -> List T
span : (T -> Boolean, List T) -> Product(List T, List T)
==
add
dropWhile(p : T -> Boolean, xs : List T) : List T ==
empty? xs => xs
p first(xs) => dropWhile(p, rest xs)
xs
span(p : T -> Boolean, xs : List T) : Product(List T, List T) ==
empty? xs => lPair([], [])
x := first xs
ys := rest xs
not p(x) => lPair([], xs)
pair := span(p, ys)
(zs := first pair; vs := second pair)
lPair(cons(x, zs), vs)
)abbrev package DCHAR1 DChar1
DChar1() : with
foo : List Character -> Product(List Character, List Character)
==
add
foo(xs : List Character) :
Product(List Character, List Character) ==
xs0 := dropWhile(x +-> x = space, xs) $ DList1(Character)
-- $ cannot be omitted
span(x +-> not digit?(x), xs0)
---------------------------------------------------------------------
Regards,
------
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.