newb question: # (1);

15 views
Skip to first unread message

Andrew Dabrowski

unread,
Jan 5, 2018, 1:52:49 PM1/5/18
to pure-lang
Why does # (1); not return 1?

> # (1,2);
2
> # (1);
#1
> # ();
0



Albert Graef

unread,
Jan 5, 2018, 1:59:37 PM1/5/18
to pure...@googlegroups.com
Well, there's no real 1-tuple in Pure, and having a fallback rule like #x=1 in the prelude might mess with user code which wants to overload # for some data structure.

Maybe the prelude shouldn't define # on tuples at all, to avoid that ugly corner case.

--
You received this message because you are subscribed to the Google Groups "pure-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pure-lang+unsubscribe@googlegroups.com.
To post to this group, send email to pure...@googlegroups.com.
Visit this group at https://groups.google.com/group/pure-lang.
For more options, visit https://groups.google.com/d/optout.



--
Dr. Albert Gr"af
Computer Music Research Group, JGU Mainz, Germany
Email:  agg...@gmail.com
WWW:    https://plus.google.com/+AlbertGraef

Andrew Dabrowski

unread,
Jan 6, 2018, 1:09:30 PM1/6/18
to pure-lang
So what's the idiomatic way to test the length of sequence?  For example if I want to do F if the length is 0, G if 1, H if longer than 1?


On Friday, January 5, 2018 at 1:59:37 PM UTC-5, aggraef wrote:
Well, there's no real 1-tuple in Pure, and having a fallback rule like #x=1 in the prelude might mess with user code which wants to overload # for some data structure.

Maybe the prelude shouldn't define # on tuples at all, to avoid that ugly corner case.
On Fri, Jan 5, 2018 at 7:11 PM, Andrew Dabrowski <unhan...@gmail.com> wrote:
Why does # (1); not return 1?

> # (1,2);
2
> # (1);
#1
> # ();
0



--
You received this message because you are subscribed to the Google Groups "pure-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pure-lang+...@googlegroups.com.

To post to this group, send email to pure...@googlegroups.com.
Visit this group at https://groups.google.com/group/pure-lang.
For more options, visit https://groups.google.com/d/optout.

John Cowan

unread,
Jan 6, 2018, 1:30:48 PM1/6/18
to pure...@googlegroups.com

On Sat, Jan 6, 2018 at 1:09 PM, Andrew Dabrowski <unhan...@gmail.com> wrote:

So what's the idiomatic way to test the length of sequence?  For example if I want to do F if the length is 0, G if 1, H if longer than 1?

In that situation it is probably better to use lists rather than tuples, because a list of a single element is distinct from the element itself.  In functional programming, tuples are normally used only when you have a fixed number of values to deal with.

-- 
John Cowan          http://vrici.lojban.org/~cowan        co...@ccil.org
What asininity could I have uttered that they applaud me thus?
        --Phocion, Greek orator


Andrew Dabrowski

unread,
Jan 6, 2018, 3:14:36 PM1/6/18
to pure-lang
Thanks!
Reply all
Reply to author
Forward
0 new messages