AssocationList or...

4 views
Skip to first unread message

Grégory Vanuxem

unread,
Jul 29, 2023, 5:31:55 AM7/29/23
to fricas...@googlegroups.com
Hello,,

I am asking myself what is the best/efficient domain to return a list
of key pairs.

I can not use List(Record), first I am not a big fan of hardcoded
"domains" in FriCAS core, and second I do not know the keys in
advance.

I explain, I am adding regular expression support to custom strings
(JuliaString) and when the regular expression captures substring they
can be named.

Take this regex:
regex:= "(?<hour>\d+):(\d+)(am|pm)?"
and "11:30 in the morning" to search in.

Actually, I return a List(JuliaString),
====================================
(7) -> l:=jlRegexMatch(regex,s)@List(JSTR)

(7) ["11", "30", ""]
Type: List(JuliaString)
====================================
But I would like to also add the (key, value) pairs support:
"hour" => "11",
"minutes" => "30"
"3" => ""
the regular expression code is in Julia (PCRE2 is used from Julia
documentation) but in FriCAS do you have any idea which domain I could
use, AssociationList is not exposed for example?

Note: that's just utility code for strings.

Regards,
__
G. Vanuxem

Waldek Hebisch

unread,
Aug 1, 2023, 4:28:21 PM8/1/23
to fricas...@googlegroups.com
On Sat, Jul 29, 2023 at 11:31:17AM +0200, Grégory Vanuxem wrote:
> Hello,,
>
> I am asking myself what is the best/efficient domain to return a list
> of key pairs.
>
> I can not use List(Record),

List of records is "best" for problem as stated above.

> first I am not a big fan of hardcoded
> "domains" in FriCAS core, and second I do not know the keys in
> advance.

AFAICS you now types of keys (String), and that is enough to define
a Record.

> I explain, I am adding regular expression support to custom strings
> (JuliaString) and when the regular expression captures substring they
> can be named.
>
> Take this regex:
> regex:= "(?<hour>\d+):(\d+)(am|pm)?"
> and "11:30 in the morning" to search in.
>
> Actually, I return a List(JuliaString),
> ====================================
> (7) -> l:=jlRegexMatch(regex,s)@List(JSTR)
>
> (7) ["11", "30", ""]
> Type: List(JuliaString)
> ====================================
> But I would like to also add the (key, value) pairs support:
> "hour" => "11",
> "minutes" => "30"
> "3" => ""
> the regular expression code is in Julia (PCRE2 is used from Julia
> documentation) but in FriCAS do you have any idea which domain I could
> use, AssociationList is not exposed for example?
>
> Note: that's just utility code for strings.

Just use AssociationList. For return values it does not matter
much if domain is exposed or not.

--
Waldek Hebisch

Grégory Vanuxem

unread,
Aug 2, 2023, 6:55:26 AM8/2/23
to fricas...@googlegroups.com
Waldek,

Le mar. 1 août 2023, 22:28, Waldek Hebisch <de...@fricas.math.uni.wroc.pl> a écrit :
On Sat, Jul 29, 2023 at 11:31:17AM +0200, Grégory Vanuxem wrote:
> Hello,,
>
> I am asking myself what is the best/efficient domain to return a list
> of key pairs.
>
> I can not use List(Record),

List of records is "best" for problem as stated above.

> first I am not a big fan of hardcoded
> "domains" in FriCAS core, and second I do not know the keys in
> advance.

AFAICS you now types of keys (String), and that is enough to define
a Record.

Yes you're probably right, I just dislike the way they are constructed. It is too internal for me as I said, I would prefer a Spad definition. After all, it not really important here.


> I explain, I am adding regular expression support to custom strings
> (JuliaString) and when the regular expression captures substring they
> can be named.
>
> Take this regex:
> regex:= "(?<hour>\d+):(\d+)(am|pm)?"
> and "11:30 in the morning" to search in.
>
> Actually, I return a List(JuliaString),
> ====================================
> (7) -> l:=jlRegexMatch(regex,s)@List(JSTR)
>
>    (7)  ["11", "30", ""]
>                                                       Type: List(JuliaString)
> ====================================
> But I would like to also add the (key, value) pairs support:
> "hour" => "11",
> "minutes" => "30"
> "3" => ""
> the regular expression code is in Julia (PCRE2 is used from Julia
> documentation) but in FriCAS do you have any idea which domain I could
> use, AssociationList is not exposed for example?
>
> Note: that's just utility code for strings.

Just use AssociationList.  For return values it does not matter
much if domain is exposed or not.

Yes, this is what I did. I looked at some piece of code and it was more easy than I thought preliminarily. 

__
Greg
Reply all
Reply to author
Forward
0 new messages