Discussion:
[fricas-devel] System error: The value |RandomFloatDistributions| is not of type SEQUENCE
Riccardo GUIDA
2018-07-13 14:50:00 UTC
Permalink
Hi

2 problems:

1) I can't understand why the function randomGraph defined in drawPoints2.input is not find in the same file. Same behavior with drawPoints.input which has a more functional style in the use of $.

2) Trying to debugging I've met a system error that might interest the developers...

Thanks in advance for any hint!
ric

(1) -> )read drawPoints2.input
randomGraph: () -> GraphImage

Type: Void
randomGraph() ==
nHues ==> 27 -- hardcoded in FriCAS :(
nPoints ==> 100

randomX == ((uniform(0,1)$RandomFloatDistributions)())::DoubleFloat
randomY == ((uniform(0,1)$RandomFloatDistributions)())::DoubleFloat
randomPoint == point([randomX, randomY])$Point DoubleFloat
randomPointColor == dark ( color(1 + (random(nHues)$Integer))$Color )
randomLineColor == dark ( color(1 + (random(nHues)$Integer))$Color )
randomPointSize == (1 + random(30)$Integer)::PositiveInteger

gim := graphImage()$GraphImage

for i in 1..nPoints repeat
component(gim, randomPoint, randomPointColor, randomLineColor, randomPointSize)$GraphImage

return gim

Type: Void

gi1:GraphImage := randomGraph()

Compiled code for randomGraph has been cleared.
Compiling body of rule randomX to compute value of type DoubleFloat
Compiling body of rule randomY to compute value of type DoubleFloat
Compiling body of rule randomPoint to compute value of type Point(
DoubleFloat)
Compiling body of rule randomPointColor to compute value of type
Palette
Compiling body of rule randomLineColor to compute value of type
Palette
Compiling body of rule randomPointSize to compute value of type
PositiveInteger
Compiling function randomGraph with type () -> GraphImage
There are no library operations named randomGraph
Use HyperDoc Browse or issue
)what op randomGraph
to learn if there is any operation containing " randomGraph " in
its name.

Cannot find a no-argument definition or library operation named
randomGraph .

(3) -> )display properties
Properties of % :
Value (has type Void): "()"
Properties of %e :
This is a system-defined macro.
macro %e () == exp(1)
Properties of %i :
This is a system-defined macro.
macro %i () == complex(0,1)
Properties of %infinity :
This is a system-defined macro.
macro %infinity () == infinity()
Properties of %minusInfinity :
This is a system-defined macro.
macro %minusInfinity () == minusInfinity()
Properties of %pi :
This is a system-defined macro.
macro %pi () == pi()
Properties of %plusInfinity :
This is a system-defined macro.
macro %plusInfinity () == plusInfinity()
Properties of SF :
This is a system-defined macro.
macro SF () == DoubleFloat()
Properties of gi1 :
Declared type or mode: GraphImage
Properties of randomGraph :
Declared type or mode: (() -> GraphImage)
This is an interpreter function.
This depends on the following functions or rules:
$elt GraphImage component randomPoint randomPointColor randomLineColor randomPointSize graphImage PositiveInteger random Integer color Color dark randomY randomX point DoubleFloat Point uniform RandomFloatDistributions /throwAway
The value |RandomFloatDistributions| is not of type SEQUENCE.

(3) -> )clear completely
All user variables and function definitions have been cleared.
All )browse facility databases have been cleared.
Internally cached functions and constructors have been cleared.
)clear completely is finished.
(1) -> )read drawPoints.input
randomGraph: () -> GraphImage

Type: Void
randomGraph() ==
nHues ==> 27 -- hardcoded in FriCAS :(
nPoints ==> 100

randomX == ((uniform$RandomFloatDistributions)(0,1)())::DoubleFloat
randomY == ((uniform$RandomFloatDistributions)(0,1)())::DoubleFloat
randomPoint == (point$Point DoubleFloat)([randomX, randomY])
randomPointColor == dark ((color$Color)(1 + (random$Integer)(nHues)))
randomLineColor == dark ((color$Color)(1 + (random$Integer)(nHues)))
randomPointSize == (1 + (random$Integer)(30))::PositiveInteger

gim := (graphImage$GraphImage)()

for i in 1..nPoints repeat
(component$GraphImage)(gim, randomPoint, randomPointColor, randomLineColor, randomPointSize)

return gim

Type: Void

gi1:GraphImage := randomGraph()

Compiled code for randomGraph has been cleared.
Compiling body of rule randomX to compute value of type DoubleFloat
Compiling body of rule randomY to compute value of type DoubleFloat
Compiling body of rule randomPoint to compute value of type Point(
DoubleFloat)
Compiling body of rule randomPointColor to compute value of type
Palette
Compiling body of rule randomLineColor to compute value of type
Palette
Compiling body of rule randomPointSize to compute value of type
PositiveInteger
Compiling function randomGraph with type () -> GraphImage
There are no library operations named randomGraph
Use HyperDoc Browse or issue
)what op randomGraph
to learn if there is any operation containing " randomGraph " in
its name.

Cannot find a no-argument definition or library operation named
randomGraph .

(3) -> )display properties
Properties of % :
Value (has type Void): "()"
Properties of %e :
This is a system-defined macro.
macro %e () == exp(1)
Properties of %i :
This is a system-defined macro.
macro %i () == complex(0,1)
Properties of %infinity :
This is a system-defined macro.
macro %infinity () == infinity()
Properties of %minusInfinity :
This is a system-defined macro.
macro %minusInfinity () == minusInfinity()
Properties of %pi :
This is a system-defined macro.
macro %pi () == pi()
Properties of %plusInfinity :
This is a system-defined macro.
macro %plusInfinity () == plusInfinity()
Properties of SF :
This is a system-defined macro.
macro SF () == DoubleFloat()
Properties of gi1 :
Declared type or mode: GraphImage
Properties of randomGraph :
Declared type or mode: (() -> GraphImage)
This is an interpreter function.
This depends on the following functions or rules:
$elt GraphImage component randomPoint randomPointColor randomLineColor randomPointSize graphImage PositiveInteger random Integer color Color dark randomY randomX point DoubleFloat Point uniform RandomFloatDistributions /throwAway
The value |RandomFloatDistributions| is not of type SEQUENCE.
--
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 post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
Riccardo GUIDA
2018-07-13 15:30:50 UTC
Permalink
PS:
If I compile my poor function I get "Apparent user error"...


(1) -> )compile RandomGraph.spad
Compiling FriCAS source code from file
/data/devel/guida/WIP/fricas_learning/RandomGraph.spad using old
system compiler.
RANGRAPH abbreviates package RandomGraph
------------------------------------------------------------------------
initializing NRLIB RANGRAPH for RandomGraph
compiling into NRLIB RANGRAPH
compiling exported randomGraph : () -> GraphImage
processing macro definition nHues ==> 27
processing macro definition nPoints ==> 100
****** comp fails at level 3 with expression: ******
error in function randomGraph

(SEQ (MDEF (|nHues|) (NIL) (NIL) 27) (MDEF (|nPoints|) (NIL) (NIL) 100)
(DEF (|randomX|) (NIL) (NIL) | << |
(|::| (((|Sel| (|RandomFloatDistributions|) |uniform|) 0 1))
(|DoubleFloat|))
| >> |)
(DEF (|randomY|) (NIL) (NIL)
(|::| (((|Sel| (|RandomFloatDistributions|) |uniform|) 0 1))
(|DoubleFloat|)))
(DEF (|randomPoint|) (NIL) (NIL)
(((|Sel| |Point| |point|) (|construct| |randomX| |randomY|))
(|DoubleFloat|)))
(DEF (|randomPointColor|) (NIL) (NIL)
(|dark|
((|Sel| (|Color|) |color|)
(+ 1 ((|Sel| (|Integer|) |random|) |nHues|)))))
(DEF (|randomLineColor|) (NIL) (NIL)
(|dark|
((|Sel| (|Color|) |color|)
(+ 1 ((|Sel| (|Integer|) |random|) |nHues|)))))
(DEF (|randomPointSize|) (NIL) (NIL)
(|::| (+ 1 ((|Sel| (|Integer|) |random|) 30)) (|PositiveInteger|)))
(|:=| |gim| ((|Sel| (|GraphImage|) |graphImage|)))
(REPEAT (IN |i| (SEGMENT 1 |nPoints|))
((|Sel| (|GraphImage|) |component|) |gim| |randomPoint|
|randomPointColor| |randomLineColor| |randomPointSize|))
(|exit| 1 (|return| |gim|)))
****** level 3 ******
$x:= (:: (((Sel (RandomFloatDistributions) uniform) (Zero) (One))) (DoubleFloat))
$m:= NIL
$f:=
((((|randomX| #) (|nPoints| #) (|nHues| #) (|randomGraph| #) ...)))
Cannot coerce (call (ELT $ 15) (call (applyFun (call (ELT $ 14) (call (CONST $ 10)) (call (CONST $ 11))))))
of mode (DoubleFloat)
to mode

(1) -> )system cat RandomGraph.spad
)abbrev package RANGRAPH RandomGraph

RandomGraph(): Exports == Implementation where
Exports == with
randomGraph: () -> GraphImage

Implementation == add
randomGraph() ==
nHues ==> 27 -- hardcoded in FriCAS :(
nPoints ==> 100

randomX == ((uniform(0,1)$RandomFloatDistributions)())::DoubleFloat
randomY == ((uniform(0,1)$RandomFloatDistributions)())::DoubleFloat
randomPoint == point([randomX, randomY])$Point DoubleFloat
randomPointColor == dark ( color(1 + (random(nHues)$Integer))$Color )
randomLineColor == dark ( color(1 + (random(nHues)$Integer))$Color )
randomPointSize == (1 + random(30)$Integer)::PositiveInteger

gim := graphImage()$GraphImage

for i in 1..nPoints repeat
component(gim, randomPoint, randomPointColor, randomLineColor, randomPointSize)$GraphImage

return gim


(1) -> randomX == ((uniform(0,1)$RandomFloatDistributions)())::DoubleFloat --- this works
Type: Void
(2) -> randomX
Compiling body of rule randomX to compute value of type DoubleFloat

(2) 0.9642863855364605
Type: DoubleFloat
(3) -> randomX

(3) 0.03437972397951383
Type: DoubleFloat
(4) ->
--
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 post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
'Martin R' via FriCAS - computer algebra system
2018-07-13 16:43:45 UTC
Permalink
some mods to make it compile...

)abbrev package RANGRAPH RandomGraph
RandomGraph(): Exports == Implementation where
Exports == with
randomGraph: () -> GraphImage

Implementation == add
randomGraph() ==
nHues ==> 27 -- hardcoded in FriCAS :(
nPoints ==> 100

randomX: DoubleFloat :=
((uniform(0,1)$RandomFloatDistributions)())::DoubleFloat
randomY: DoubleFloat :=
((uniform(0,1)$RandomFloatDistributions)())::DoubleFloat
randomPoint := point([randomX, randomY])$Point(DoubleFloat)
randomPointColor := dark(color(1 +
(random(nHues)$Integer))$Color)$Palette
randomLineColor := dark( color(1 +
(random(nHues)$Integer))$Color)$Palette
randomPointSize := (1 + random(30)$Integer)::PositiveInteger

gim: GraphImage := graphImage()$GraphImage

for i in 1..nPoints repeat
component(gim, randomPoint, randomPointColor,
randomLineColor, randomPointSize)$GraphImage

return gim
--
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 post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
oldk1331
2018-07-14 07:23:25 UTC
Permalink
Hi, the root problem is that you defined function inside function,
the following simple example won't work:

f2 : () -> Float
f2()==
f3 == 3.0
f3()

Sadly that FriCAS has suffered from the "variable scope" and
"proper closure" problem for a long time.
--
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 post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
Loading...