Re: [Fish-users] default function parameters

2017-08-18 Thread Kurtis Rader
On Fri, Aug 18, 2017 at 5:53 PM, Mark Volkmann wrote: > I was so close! > I had this: > set -q language; or set language 'english' > > Why do I need the [1] part? > Because fish vars can be set but have no value. Every fish var is an array which can have zero, one, or

Re: [Fish-users] default function parameters

2017-08-18 Thread Mark Volkmann
I was so close! I had this: set -q language; or set language 'english' Why do I need the [1] part? On Fri, Aug 18, 2017 at 5:51 PM, Kurtis Rader wrote: > Add this to the top of the function: > > set -q language[1] > or set language english > > On Fri, Aug 18, 2017 at 3:25

Re: [Fish-users] default function parameters

2017-08-18 Thread Kurtis Rader
On Fri, Aug 18, 2017 at 4:12 PM, Greg Reagle wrote: > On Fri, Aug 18, 2017, at 18:51, Kurtis Rader wrote: > > Add this to the top of the function: > > > > set -q language[1] > > or set language english > > There is a potential problem with the above though. If $language is

Re: [Fish-users] default function parameters

2017-08-18 Thread Greg Reagle
On Fri, Aug 18, 2017, at 18:51, Kurtis Rader wrote: > Add this to the top of the function: > > set -q language[1] > or set language english There is a potential problem with the above though. If $language is set to the empty string, the above code will not set language to english [1]. I say

Re: [Fish-users] default function parameters

2017-08-18 Thread Kurtis Rader
Add this to the top of the function: set -q language[1] or set language english On Fri, Aug 18, 2017 at 3:25 PM, Mark Volkmann wrote: > What's the best way to provide a default value for a function parameter? > For example, suppose I have a function like this: > >

[Fish-users] default function parameters

2017-08-18 Thread Mark Volkmann
What's the best way to provide a default value for a function parameter? For example, suppose I have a function like this: function greet -a name language switch "$language" case 'english' echo 'Hello, '$name case 'spanish' echo 'Hola, '$name case '*' echo