Fuck lists and their overhead. I just want an extension to C that lets me return vectors. Not classes, not structs, and nothing involving preprocessor shit either. Something like: <int, int> divr(int a, int b){ return < a / b, a % b >; } int main(int asdfasdf, char ** qwerqwe){ int touhous = 5, men = 12; int eachSucked, unsucked; <eachSucked, unsucked> = divr(men, touhous); printf("Each of the %d touhous sucked %d cocks, and there were %d left unsucked", touhous, eachSucked, unsucked); return 0; } which would compile to something simple, like:divr: pop eax pop ebx push edx xor edx, edx idiv ebx mov ebx, edx pop edx push ebx push eax ret main: touhous dd 5 men dd 12 eachSucked dd ? unsucked dd ? push touhous push men jmp divr pop [eachSucked] pop [unsucked] ;; blah blah blah, printf goes here Isn't that much more elegant that a nasty list every time where things have to be inserted or initialized? Oh, and if you don't need a return value, <a,b,NULL, c> will compile the unneeded return value out, or at least discard the result.
Name:
Anonymous2014-06-13 0:01
ts, and nothing involving preprocessor shit either. Something like: <int, int> divr(int a, int b){ return < a / b, a % b >; } int main(int asdfasdf, char ** qwerqwe){ int virgins = over 9000, women = 3; int eachVirgin, unvirgin; <eachVirgin, unvirgin> = divr(virgins, women); printf("Each of the %d women had boyfriends %d and the virgins %d were left eachVirgin", women, eachVirgin, unvirgin); return 0; } which would compile to something simple, like:divr: pop eax pop ebx push edx xor edx, edx idiv ebx mov ebx, edx pop edx push ebx push eax ret main: women dd 3 virgins dd 9001 eachVirgin dd ? unvirgin dd ? push women push virgins jmp divr pop [eachVirgin] pop [unvirgin] ;; blah blah blah, printf goes here Isn't that much more elegant that a nasty list every time where things have to be inserted or initialized? Oh, and if you don't need a return value, <a,b,NULL, c> will compile the unneeded return value out, or at least discard the result.
I've implemented vector valued return in Symta, unoptimized, but as far as I can see it would still require copying between stack-frames, unless the return vector's size is know statially. In that case we can preallocate memory at call site's stack frame. Anyway, I'm using vectors for lists, because they are so much more efficient than cons-lists.
Name:
Anonymous2014-06-13 4:38
u mena tuple?
Name:
Anonymous2014-06-13 8:49
>>5 Destructive side effects are the problem. Your divr does something besides returning a value!
Name:
Anonymous2014-06-13 8:57
>>8 I dissagree, this works like prolog's way of doing this
>>8 That would be bad only if computers were magical math machines operating on infinite memory. In reality they have finite memory and destructive updates are sometimes necessary.
>>13 Are you disgusted by the impure, destructive update in divr?
Name:
Anonymous2014-06-13 11:23
>>8 Okay, in academia, you would be right. That is not theoretically the right way to express multiple return values, because side effects. In the industry, we actually run our code, and that means it has side effects.
Name:
What is Your Favorite Food?2014-06-13 11:30
>>15 Purity is an obvious advantage in industry. It makes the code more modular and easier to reason about. On the other hand, destructive updates are "spooky action at a distance" and thus a source of bugs.
Name:
Anonymous2014-06-13 11:33
>>16 Sure buddy, let's see you write a program that prints "hello world" while not having any side effects. You go ahead and do that.
Name:
Anonymous2014-06-13 11:44
>>17 If black-and-white thinking is what thrives "in industry", then it's a shitty industry. No one is talking about total elimination of side effects, only about their clean, explicit isolation. If a function is performing side effects, fine - just declare it. If a function is performing only a transformation of some input value to a result value, then it should do just that, without being entangled with the whole program state. Because if having a 100 functions each of which could modify the program state is worse than having 10 of them and 90 functions which do their job without touching state.
>>20 Considering there are no universes but this one.
Name:
Anonymous2014-06-13 15:57
>>4 Typing. What if I wanted to return <int, float, char *>? The best I could do is enum type{INT, FLOAT, CHARP}; struct __ret{void * data; enum type thisType}; struct __ret * funct(...){ int a = 1402624235; float b = 2.76; char c[] = "Lolies[i]![/i]"; struct __ret * ret = (struct __ret*) malloc(3 * sizeof(struct __ret)); ret[0].data = &a; ret[1].data = &a; ret[2].data = &a; ret[0].data = INT; ret[0].data = FLOAT; ret[0].data = CHARP; return 0; } Does that look good to you? Might as well just use an untyped list.
>>5 No, no, NO. None of that `put output in one of the parameters' shit. The only valid case for shit like that is maybe something like scanf(), but I suspect better solutions to that as well.
>>6 Well, I made this post with static (or at least deterministic at compile-time) sizes for the return vectors.
Name:
>>1,242014-06-13 15:58
>>24 where ret[0].data = INT; ret[0].data = FLOAT; ret[0].data = CHARP; is actually ret[0].thisType = INT; ret[1].thisType= FLOAT; ret[2].thisType = CHARP; , of course.
>>26 But I don't want any other language; I want C with just one tiny addition that may or may not require massive changes to optimization, machine code generation, and calling conventions.
>>36 because when you put pin the tag through the union it ruptures the cells causing LF to be produced which will sting the eyes and this cathode raygun monitor from 1982 is already causing me enough eyestrain thankyouverymuch