libraries

7 views
Skip to first unread message

Wink Saville

unread,
Jun 18, 2020, 12:49:23 AM6/18/20
to Curv
I am thinking about the future and I can see myself creating many libraries. I'm starting on lib-airfoil.curv and one of the functions I've created is "normailize".  I can imagine I might create different library in the future that also has a "normalize" function.

How can I use two different libraries that might have conflicting names?

An example, currently I can do something like this:

$ cat -n x.curv
     1 do
     2  // Load the library
     3  local include file "lib-airfoil.curv";
     4
     5  // Define an array of x,y points that is the airfoil section
     6  local af = [[4, 0], [1 ,1], [0, 0], [1, 0]];
     7
     8  // call the normalize function in lib-airfoil.curv and set nAf.
     9  local nAf = normalize(af);
    10 in
    11  polygon nAf >> scale 10
    12



But I'd like to do something like below, where I include lib-airfoil.curv
and assign it to a "local" name, "laf". Then use record syntax to execute
"local nAf = laf.normalize(af)":

$ cat -n y.curv
     1 do
     2  // Load the library
     3  local laf = include file "lib-airfoil.curv";
     4
     5  // Define an array of x,y points that is the airfoil section
     6  local af = [[4, 0], [1 ,1], [0, 0], [1, 0]];
     7  
     8  // call the laf.normalize function in lib-airfoil.curv and set nAf.
     9  local nAf = laf.normalize(af);
    10 in
    11  polygon nAf >> scale 10
    12


Of course the syntax doesn't work:

curv -l y.curv
ERROR: syntax error
at file "y.curv":
3|   local laf = include file "lib-airfoil.curv";
                 ^^^^^^^                        

So is there a syntax that can solve the problem?

Alexandre François Garreau

unread,
Jun 18, 2020, 5:15:37 AM6/18/20
to cu...@googlegroups.com
Le jeudi 18 juin 2020, 06:49:10 CEST Wink Saville a écrit :
> curv -l y.curv
> ERROR: syntax error
> at file "y.curv":
> 3| local laf = include file "lib-airfoil.curv";
> ^^^^^^^
>
> So is there a syntax that can solve the problem?

I’m rusty but aren’t you meant to remove “include” and let only “file” when
assigning it? Afair curv libraries work exactly like that: they’re
records that are loaded into variables and then accessed by dotted
notation.

I also note that syntax error seems not verbose enough to describe the
problem (only stating there is one), or am I wrong?

Doug Moen

unread,
Jun 18, 2020, 6:47:58 AM6/18/20
to Curv
Alexandre is correct.

'file "lib-airfoil.curv"' is an expression that returns a record value.
Try it in the REPL:
curv> file "lib-airfoil.curv"

'include <record-expression>' is definition syntax that defines a variable for each field in a record value.
Similar to "from module import *" in Python, if you know Python.
Try it in the REPL:
curv> include {a:1,b:2}
curv> a
1
curv> b
2
> --
> You received this message because you are subscribed to the Google
> Groups "Curv" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to curv+uns...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/curv/3452764.5Zu8EI35I5%40galex-713.eu.
>

Wink Saville

unread,
Jun 18, 2020, 11:54:13 AM6/18/20
to Curv
Simply removing "include" from line 3 and worked on my "y.curv" file:

$ cat -n y.curv
     1 do
     2   // Load the library
     3   local laf = file "lib-airfoil.curv";
     4
     5   // Define an array of x,y points that is the airfoil section
     6   local af = [[4, 0], [1 ,1], [0, 0], [1, 0]];
     7   
     8   // call the laf.normalize function in lib-airfoil.curv and set nAf.
     9   local nAf = laf.normalize(af);
    10 in
    11   polygon nAf >> scale 10
    12

THANKS, to both of you!
Reply all
Reply to author
Forward
0 new messages