Bill Allombert on Mon, 14 Oct 2024 19:13:36 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: question on the apply function, when the return values > 1


On Mon, Oct 14, 2024 at 09:54:37AM -0700, American Citizen wrote:
> Bill:
> 
> This is an elegant solution.
> 
> > There is shorter alternative without apply and concat.
> > [[x,y]|x<-130*L;y<-ellordinate(e, x)]
> > 
> > (beware the semi-colon in the middle).
> > 
> > Cheers,
> > Bill.
> > 
> Is the pipe like the pipe in Linux? and what exactly does the semi-colon do
> here?

This is the same character as the pipe in the shell, yes.

Both the | and the ; allow for <- to be read as a single token (arrow) rather
than two, < (inferior) and - (minus) (think x < -130*L )

x (arrow) L mean: pick all x in the vector L in order.

You can also add a selector with a comma:

? [p^2 | p<-primes(10), p%4==3]
%2 = [9,49,121,361,529]

Cheers,
Bill.