Hi, another workaround I discovered is to use anonymous function:
getA := (r:R):INT +-> r.a
On 11/10/19 8:52 PM, Ralf Hemmecke wrote:
> Hello Paul,
>
> I'm not a compiler developer, but if you are not afraid of writing a
> short spad program, then you can get around it, see attachment.
>
> )compile rec.spad
>
>
> (2) -> x := makeRec(2,3)
>
> (2) [a = 3, b = 2]
> Type: MyRec
> (3) -> recA(x)
>
> (3) 3
> Type: PositiveInteger
> (4) -> a := 0
>
> (4) 0
> Type: NonNegativeInteger
> (5) -> recA(x)
>
> (5) 3
> Type: PositiveInteger
>
> If you don't want to do this, you must wait for some smarter person that
> tells you how to define getA in order to refer to the right a.
>
> I've found another workaround.
>
> (1) -> Z ==> Integer
> Type: Void
> (2) -> R ==> Record(a: Z, b: Z)
> Type: Void
> (3) -> makeR(x:Integer, y:Integer):R == [x,y]
> Function declaration makeR : (Integer, Integer) -> Record(a: Integer
> ,b: Integer) has been added to workspace.
> Type: Void
> (4) -> aForGetA := 'a
>
> (4) a
> Type: Variable(a)
> (5) -> getA(r:R):Integer == r.aForGetA
> Function declaration getA : Record(a: Integer,b: Integer) -> Integer
> has been added to workspace.
> Type: Void
> (6) -> r := makeR(3, 5)
> Compiling function makeR with type (Integer, Integer) -> Record(a:
> Integer,b: Integer)
>
> (6) [a = 3, b = 5]
> Type: Record(a: Integer,b: Integer)
> (7) -> getA(r)
> Compiling function getA with type Record(a: Integer,b: Integer) ->
> Integer
>
> (7) 3
> Type: PositiveInteger
> (8) -> a := 0
>
> (8) 0
> Type: NonNegativeInteger
> (9) -> getA r
>
> (9) 3
>
>
> 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/c7ad4964-91e5-6e64-9264-e8401424c09f%40gmail.com.