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| #) ...)))
>> Apparent user error:
   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+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to