ezequielc / chromey-calculator

Automatically exported from code.google.com/p/chromey-calculator
1 stars 0 forks source link

Add user functions #14

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This shouldn't be hard to do. Functions would be set by doing:
 @func_name(argname1, a2, z) = @@argname1 * @@a2 ^ @@z
and called with:
 @name("arg1", "arg2")

Here's a real example (would convert degrees to radians):
 @rad(d) = @@d degrees in radians
Example usage:
 @rad("180") =
 3.14159265 radians

Rules for defining functions:
* Format: @<name>([<args>]) = <body>
* The name must contain 1 or more letters, numbers, and/or underscores.
* The (optional) args should contain a comma+space separated list of arguments, 
each of which must contain 1 or 
more letters, numbers, and/or underscores.
* The body of the function should be a regular input (except for the 
arguments). Variables and arguments can be 
accessed, and other functions can be called. Arguments are accessed with 
@@<argname>.

Rules for calling functions:
* Format: @<name>([<args>])
* The name must be a valid, defined function name.
* I'm not so sure about the arguments, mainly because of nesting problems 
(which have always confused me :/). I'd 
say a comma+space separated list of normal inputs, but then you have nesting 
problems and maybe comma problems. 
Maybe arguments should be wrapped in double quotes? Then it would be waay 
easier, and having \ escape " would be 
very easy to do.

So yeah, adding functions shouldn't be too hard. Writing this up was probably 
harder, I felt like doing it though 
:P

Original issue reported on code.google.com by mindstormskd@gmail.com on 9 Feb 2010 at 4:19

GoogleCodeExporter commented 9 years ago
Cool. When we do this, let's make sure to keep code for this in it's own js 
file and 
implement it in a way we can easily enable/disable the feature. I think we may 
have to 
go through a few iterations to get this feature just right.

Original comment by bwrobin...@gmail.com on 9 Feb 2010 at 8:52

GoogleCodeExporter commented 9 years ago
Oops, forgot to say that the number of arguments passed when calling a function 
must be 
the same as when it was defined.

@bwrobinett, should we move the entire variable system into another js file, 
like we 
did with history.js? I was thinking functions would be part of the existing 
variable 
system.

Original comment by mindstormskd@gmail.com on 9 Feb 2010 at 6:32

GoogleCodeExporter commented 9 years ago
Let's do the rewrite first (issue 15).
We should start a wave on user functions... I'm thinking of going in a 
different 
direction. Could be really cool.

Original comment by bwrobin...@gmail.com on 9 Feb 2010 at 9:11

GoogleCodeExporter commented 9 years ago
<quote>
Comment by marc.pen...@gmail.com, Jan 25, 2011
How do I go about designing code for this? For example, as a accounting 
student, it would be handy to have a present value function.
</quote>

Looks like marc's sort of request could be solved or at least triaged by 
supporting user functions.

Original comment by iisi50...@gmail.com on 14 Sep 2011 at 6:53