Ralf,

Yes, thank you, that is very interesting and useful.
I did not know about 'Any'. I wish I had come across this earlier (but
how would I?). I do think you should put an explanation into some help
section where potential new users are likely to find it, especially
people starting to program in SPAD who have come from other languages.

I find this type of paradigm very powerful where you do some operation
on a whole collection by calling the same function on all its parts,
even if they are different types. I think that other people would try to
do this if they came from other languages. At first glance, it looks
like there is more boilerplate in SPAD but at least it can be done.

I will also look in AssociationList.html etc to look at key:value pairs
and see if this could be extended to implement something like database
tables.

Thanks again, Martin

On 12/02/2025 16:39, 'Ralf Hemmecke' via FriCAS - computer algebra
system wrote:
On 2/11/25 15:44, Martin Baker wrote:
might work like the concept of Dictionaries in Python which are used
to store data values in key:value pairs.

Is already available in FriCAS in several domains.

http://fricas.github.io/api/AssociationList.html
http://fricas.github.io/api/HashTable.html
http://fricas.github.io/api/XHashTable.html

There was some difference that always used to cause me problems
because categories are more statically defined than interfaces but I
have forgotten the details now.

I suggest you read the Aldor User Guide.

http://www.aldor.org/docs/aldorug.pdf

For example, in Java you might have an interface called 'shape' and
this interface has functions such as 'draw' so classes that
implement shape such as 'square' and 'circle' all have there own
implementations of 'draw'.

But that is exactly the same as in SPAD.
Categories can provide implementations of some functions.
One should, however, take care that such implementations do not rely on
any representation details of an element. Such implementations can be
overridden by an respective domain, but the general idea is that
categories do not know about the representation. It's just an abstract
collection of function signatures without the notion of the concrete
carrier set is one speaks in terms of universal algebras (or rather
multisorted algebras).

Some other part of the code may have a List of 'shape' and if you
call 'draw' on each of the elements it would call the appropriate
version of draw depending on whether it is a 'square' or a 'circle'.

That you can also do in FriCAS, but it is not exactly the way you do it
in Java. A list must have elements of the same type, i.e. in FriCAS you
can only have List(T) for a concrete type T. If you have Circle and
Square as domains realizing the category Shape, then you can either have
List(Circle) or List(Square), but not a mixture of them. What you need
is a domain, that "represents" both of them. You find such a general
domain describe in Section 21.10 in aldorug.pdf, the domain "Object".
That domain is also in FriCAS and is called "Any". And yes, it bundles
an element together with its type information. (That is what all object-
oriented programming languages do per default.)
In FriCAS/Aldor an element (i.e. its representation in memory) usually
does not know its type, (i.e. there is no reference to the respective
domain). The "Any", "Object" construction makes this explicit. In that
sense, FriCAS/Aldor is different from other OO programming languages.

I mention this just as a reminder of the sort of problems new users
may have when coming to SPAD from other languages. I think it would
be good if there was something on fricas.github.io listing potential
issues like this for new users (and me).
Maybe I should add such an explanation into some help section if the
above at least helps you. (Feedback appreciated.)

Ralf


--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/f3649c7b-1276-4633-8354-d32177d458a3%40martinb.com.

Reply via email to