Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

hai prog: multiple return values

Name: Anonymous 2009-10-02 19:31

Hello

I know one can use pass-by-reference for getting multiple values back from a function, but is there a language that allows you to actually define multiple outputs seperate from the parameter list for super neatness.

I was thinking it would be super-cool to have an auto-defined struct based on the function return values. so in some pseudo-language it would be like...


def splitstring  string<s char<sep string>a string>b

s = "hello world"

splitstring s ' '

printf(splitstring.a)
printf(splitstring.b)


would that be totally kawaii aewsome?

obviously each thread would have its only instances of these auto-structs.

Name: Anonymous 2009-10-05 5:02

>>38+>>39

5/20

Name: Anonymous 2009-10-05 5:53

>>41
wait.... what?
3/10 + 2/10 = 5/10

Name: Anonymous 2009-10-05 5:58

>>42
You're adding two separate data sets

Name: Anonymous 2009-10-05 7:54

>>34
I have some interesting facts for you.

>>> def f(): return (1, 2), "valid python code"
...
>>> f()
((1, 2), 'valid python code')
>>> t = f()
>>> t
((1, 2), 'valid python code')
>>> x, y = f()
>>> x, y
((1, 2), 'valid python code')
>>> f()
((1, 2), 'valid python code')
>>> (a, b), c = f()
>>> a, b, c
(1, 2, 'valid python code')
>>> def dot((x1, y1), (x2, y2)): return x1 * x2 + y1 * y2
...
>>> p1, p2 = (1, 0), (0, 1)
>>> dot(p1, p2)
0
>>> lst = x, [y, z] = [1, (2, 3)]
>>> lst
[1, (2, 3)]
>>> x, y, z
(1, 2, 3)


As you do indeed resemble the invisible poster in certain respects, I feel I'd save everyone's time by explaining up front: Python has fully functional destructuring bind built in and it works in assignments, on function calls, everywhere. By the way, RHS can be any iterable, not just tuple or list.

There are three differences from the lithtth protheththing language:

1. It's somewhat less powerful -- there are no named/rest arguments. Actually "*xs, x = (1, 2, 3)" works in Py3K, but on the other hand they pulled automatic destructuring in lambda arguments or something because Guido hates lithp weenies and wants to drive them away, no matter the cost.

2. You never need to actually call some macro to have it. It just works.

3. Excessive parentheses do not make you want to gouge your eyes out with a soup ladle.

Name: Anonymous 2009-10-05 11:30

>>44
Excessive parentheses do not make you want to gouge your eyes out with a soup ladle.
The FORCED INDENTATION OF CODE does though.

Name: Anonymous 2009-10-05 12:36

>>44
GOD HATES LISP

Name: Anonymous 2009-10-05 12:39

>>46
Well, maybe your shitty god

Name: Anonymous 2009-10-05 12:42

>>47
Albeson doesnt count either numbnuts

Name: Anonymous 2009-10-05 13:26

The cool thing to do is assigning by binding pattern matching, like in Erlang and Oz.

Name: Anonymous 2009-10-05 15:25

>>44
Actually, I started using Scheme the other week after lots of time spent with Sepples and FOIC. With proper parenthesis matching as in DrScheme, it's not half bad.

It's hard to explain, but it's almost like demon code. It sort of summons itself to the capable programmer's hands. You should give it a shot if you haven't.

Name: Anonymous 2009-10-05 22:43

>>45
Oh yeah, indentation of code surely makes it hard to read. Idiots.
>>44
Only sensible post in this thread.

Name: Anonymous 2009-10-05 23:16

>>51
It has been proven that not only does indentation of code reduce productivity, but that it also reduces readability, especially when there is a rigid implementation which lacks curly brackets, like in languages such as Python and Visual Basic.

Name: Anonymous 2009-10-06 0:16

>>52
>it has been proven that indentation of code reduces productivity and also reduces readability
ಠ_ಠ

Name: Anonymous 2009-10-06 0:43

>>52
 links or no proof.

Name: Anonymous 2009-10-06 1:49

>>52
Hello, Frozen. Your English got better.

Name: Anonymous 2009-10-06 2:05

>>53,55

#include <stdio>

int main (int argc, char **argv)
{
   int foo = 1;
   char bar = 'a';

   if (foo == 1)
   {
      printf("bar: %c", bar);
   }

   return 0;
}
[code]

or

[code]
foo = 1
bar = '1'

if foo == 1:
   print "bar: " + bar

return 0


I can assure you, not only did the second one take longer to write per line (because you have to consciously look at indentation and remember where you are), but it took longer to read (per line).  This is a simple program, too.  Imagine a full blown program, like an operating system.  This is why they don't write operating systems in languages such as Python.

Name: Anonymous 2009-10-06 3:18

Name: 53 2009-10-06 3:30

>>56
oh. i thought you meant indentation in general, not indentation alone.
yeah, braces + indentation is definitely superior.

Name: Anonymous 2009-10-07 20:02

arg1 + 3 returned in ax
3 * (arg1 + 3) returned in bx


push bp
mov bp, sp
mov ax, [bp+4]
add ax, 3
mov bx, ax
imul ax, 3
mov sp, bp
pop bp
ret

Name: Anonymous 2009-10-07 20:03

>>59
otherway around i mean

Name: Anonymous 2009-10-07 21:55

>>56
This is why they don't write operating systems in languages such as Python.
Holy fuck. You honestly believe *indentation* is the only reason they aren't writing operating systems in Python.

You, sir, are completely out to lunch. You must be stoned, or trolling, or something. There's no possible way any serious person in their right mind could make such a statement.

Name: >>56 2009-10-07 21:57

>>61
PROTIP: YHBT

Name: Anonymous 2009-10-07 21:58

There's an operating system in Haskell.

Name: Anonymous 2009-10-07 22:03

>>62
I think you just fell for a rather blatant meta-troll

Name: 62 2009-10-07 22:14

>>64
IHBMT

Name: Anonymous 2009-10-07 23:19

I have to admit, I am a bit unsure as to the exact troll status in this thread. Is there a parser for this?

Name: Anonymous 2009-10-07 23:22

Do not worry for whom the board trolls; it trolls for thee.

Name: Anonymous 2009-10-08 6:29

>>67
That's beautiful, man ಥ_ಥ

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List