fricas get setelt etc.

18 views
Skip to first unread message

Grégory Vanuxem

unread,
May 14, 2024, 12:59:13 PM5/14/24
to fricas...@googlegroups.com
I am not on a computer.

Is it possible to get a property in Spad, like C++ for example, like ojb.truc?

Not like a Record I have to check first. And not not a number

- Greg

Waldek Hebisch

unread,
May 14, 2024, 4:41:07 PM5/14/24
to fricas...@googlegroups.com
It is not clear to me what you want. Note that in FriCAS _everything_
visible outside a domain is a function. That includes "setters",
that is functions which as a side effect assign value to variables
or part of variables (in case of composite types). If your
function is called 'setelt!', then you can use assignment syntax
when calling such functions.

Also, outside domains one can only access exported functionality.
I you need access to something internal, then you must first
export appropriate functions (and recompile the domain).
If you want you can add 'setelt!', including Record-like.

--
Waldek Hebisch

Grégory Vanuxem

unread,
May 15, 2024, 8:10:01 PM5/15/24
to fricas...@googlegroups.com
Hello Waldek,

Exactly what I was looking for. Thanks.

I thought only integer based indexing was allowed, and since Record is
a FriCAS primitive I thought indexing by Symbol, or whatever, was not
possible.

- Greg
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/ZkPMYMb84nshl7BI%40fricas.org.

Waldek Hebisch

unread,
May 15, 2024, 8:36:35 PM5/15/24
to fricas...@googlegroups.com
On Thu, May 16, 2024 at 02:09:21AM +0200, Grégory Vanuxem wrote:
> Hello Waldek,
>
> Exactly what I was looking for. Thanks.
>
> I thought only integer based indexing was allowed, and since Record is
> a FriCAS primitive I thought indexing by Symbol, or whatever, was not
> possible.

Note that hash tables have keys which can be of type Symbol,
so "indexing" is easy. But if different symbols need different code,
than user would need to implement appropriate runtime dispatch.
'setelt!' can be overloaded, and that is used to invoke different code
for each selector.

If you want to use 'a.type := x' declare 'setelt' like:

setelt! : (%, "type", N) -> N

Matching 'elt' would be:

elt : (%, "type") -> N


--
Waldek Hebisch

Grégory Vanuxem

unread,
May 15, 2024, 9:08:40 PM5/15/24
to fricas...@googlegroups.com
I have seen that now. And the "quick" versions are not used. That's
very handy. In fact, again with Julia, this is just to be a little
more complete with usual returned values from Julia, I just added
access to properties/fields of Julia objects:

(35) -> a:=nrand(4,4)

(35) -1.42136 -1.742 0.979898 -0.48064
-0.0343245 0.602809 1.58283 -0.859754
-2.6258 -1.35866 1.83935 0.420829
1.71514 -0.529176 -1.43319 0.578933
Type: JuliaFloat64Matrix
Time: 0.01 sec
(36) -> svd:=jlApply("svd", nrand(4,4)::JOBJECT)

(36)
SVD{Float64, Float64, Matrix{Float64}, Vector{Float64}}
U factor:
4×4 Matrix{Float64}:
0.417831 -0.57559 -0.400583 -0.577622
0.866547 0.270253 0.413597 0.0706958
-0.138286 0.653413 -0.01002 -0.744196
0.235353 0.410745 -0.817539 0.327913
singular values:
4-element Vector{Float64}:
3.088850520328464
1.3640765718602572
0.3053658244498711
0.08269730187774406
Vt factor:
4×4 Matrix{Float64}:
0.143299 0.562979 -0.73529 -0.349096
0.903295 -0.0780267 -0.0803261 0.414148
0.120522 -0.792531 -0.354939 -0.481027
0.386003 0.221045 0.571764 -0.689367
Type: JuliaObject
Time: 0.02 (EV) = 0.03 sec
(38) -> jlApply("*", svd.U, jlApply("transpose", (svd.U)))

(38)
4×4 Matrix{Float64}:
1.0 -6.36168e-18 1.47838e-16 -4.17e-18
-6.36168e-18 1.0 1.52234e-16 -8.99941e-17
1.47838e-16 1.52234e-16 1.0 -2.40414e-16
-4.17e-18 -8.99941e-17 -2.40414e-16 1.0
Type: JuliaObject
Time: 0.01 sec

Ralf Hemmecke

unread,
May 16, 2024, 1:19:42 AM5/16/24
to fricas...@googlegroups.com
Maybe this might also be connected.

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

The Key can be any Hashable type.

Ralf
Reply all
Reply to author
Forward
0 new messages