Functions
complete
Zac @ Soulver
complete
Custom (natural language) functions are a tentpole feature in a new experimental version of Soulver called X1. More details here: https://soulver.app/x
Mike Schinkel
Zac @ Soulver —
Mike Schinkel
He was supposed to be dancing. 😟
n
nylas
Would love to see support for this. Even in a very simple form, like:
calcit(a, b, c) = (a + b + c)
foo = calcit(1,2,3)
bar = calcit(4,5,6)
squareit(x) = x^2
and so on
Will
If it ends up being difficult to find a syntax for function definition that feels right and fits within the existing Soulver syntax, another option could be to separate function from data. It could work in a few ways:
* Let the user define functions in Soulver's settings alongside Global Variables that they can use. When sharing a sheet with others, include any globally defined functions that the sheet depends on. When another user imports the sheet, prompt them to add these required functions to their global custom function library. On a conflicting name, ask for a new name and update any references to the function in the sheet.
* Instead of defining functions globally, let the user define them as part of the metadata of a sheet.
Zac @ Soulver
Will: This is a sensible suggestion. I'm working on something along these lines, where you can define your own preferred function syntaxes.
S
Stephen Wheatcraft
If you mean x and y to be expressions, this would be great. But our example is just two numbers, and the min of two numbers is immediately obvious (at least it seems to to me), so it wouldn't be useful if x and y are just numbers.
Tim Bates
Supporting region-specific delimiters in function input seems to be a costly straightjacket. When calling a function, you could require a period for decimal and no thousands delimitters in bare numbers. That would also allow support for soulver's multi-word variables. I think many users would appreciate the extra structure of brackets and comma delimitters.
min(1000.32, foo)
min(my dog, my cat)
Regarding syntax, I had thought that something C/R like would be comfortable for the biggest set of users, e.g.
min = function(x, y){ if (x < y) then x else y}
But seeing the approach of treating all formulas as function bodies discussed below, that looks preferable. So elegant to define a variable, then use that definition as a function simply by appending () to the variable name!…
min = if x < y then x else y
min(3, 4 ) // outputs 3
min(x=3, y=4) // outputs 3
(still prefer the comma delimiter - reduced the mental work load of groking the input string
Mike Schinkel
Something to consider; for functions to be really useful, having a concept of “global” across sheets would be really beneficial, similar to this feature request:
That way we could create a sheet of functions we use and add to it over time.
Zac @ Soulver
planned
J
Jamie Bullock
I would also love to see user-defined functions implemented, however my vote would go with the more standard parenthesised syntax, so:
min(x, y) = if x < y then x else y
Used:
min(0, 1)
This is also more consistent with Soulver's built-in functions.
Zac @ Soulver
Jamie Bullock: Using a comma as a parameter separator is a bit of an issue for Soulver. It's fine in programming languages where dot is the only valid decimal point, but Soulver supports European style numbers where a comma is a decimal point.
J
Jamie Bullock
Zac @ Soulver: ah, makes sense. In that case, I would still prefer the parentheses.
min(x y) = if x < y then x else y
min(0 1)
Zac @ Soulver
Jamie Bullock: Spaces are thousands separators in Russia and Norway 😓.
J
Jamie Bullock
Zac @ Soulver: Haha... yikes. Personally I'd be happy with functions initially only supporting a single argument, like the built-in ones. That would still be useful.
For multiple args, I suppose an Objective-C sequel solution is potentially an option...
min(x:0 y:1)
But this doesn't feel very Soulvery!
Zac @ Soulver
Jamie Bullock: Yeah I was thinking something like that too (named parameters using a colon).
Zac @ Soulver
You could also use a colon as a separator without the labels, like min(0:1).
J
Jamie Bullock
Zac @ Soulver: Neat. Yeah, this feels like a good solution.
Daniil Kolesnichenko
Zac @ Soulver: maybe consider semicolon instead? min(0; 1) looks more readable IMO plus as a bonus it's a bit faster to type (which is kinda nice if you use functions a lot).
Zac @ Soulver
under review
Zac @ Soulver
Interesting idea!
Load More
→