int foo()
{
// Create two 1000x1000 unit matrices:
Matrix a, b, c;
if(!Matrix_init(&a, 1000, 1000)) goto exit_foo;
if(!Matrix_init(&b, 1000, 1000)) goto exit_foo;
// Do something with a and b here, for example:
if(!Matrix_init_with_matrix(&c, &a)) goto exit_foo;
if(!Matrix_multiply_by_constant(&c, 2)) goto exit_foo;
if(!Matrix_add(&c, &b)) goto exit_foo;
...
int foo()
{
// Create two 1000x1000 unit matrices:
Matrix a, b, c;
if(Matrix_init(&a, 1000, 1000))
{
if(Matrix_init(&b, 1000, 1000))
{
// Do something with a and b here, for example:
if(Matrix_init_with_matrix(&c, &a))
{
if(Matrix_multiply_by_constant(&c, 2))
{
if(Matrix_add(&c, &b))
{
...
}
}
}
}
}
Tried to write a windows application in C. The language is really not suited for it. I barely got anywhere before I gave up. Ugly fucking code. Ugly. It was so ugly.
GC approved GOTO
(define (foo)
(let ((some-value 0)
(a (matrix))
(b (matrix))
(c (matrix)))
(call-with-current-continuation
(lambda (goto-exit-foo)
(unless (matrix-init! a 1000 1000) (goto-exit-foo))
(unless (matrix-init! b 1000 1000) (goto-exit-foo))
(unless (matrix-init-with-matrix! c a) (goto-exit-foo))
(unless (matrix-multiply-by-constant! c 2) (goto-exit-foo))
(unless (matrix-add! c b) (goto-exit-foo))
...
)
)
;exit-foo:
(matrix-free! a)
(matrix-free! b)
(matrix-free! c)
some-value
)
)
Name:
Anonymous2011-10-28 8:11
>>59 call/cc is way more powerful than goto (it's also typically less efficient, but this depends on how it's implemented, it's possible theoretically to implement it more efficiently, but that may come at the cost of total program speed(implementation-dependent)).
Common Lisp's go special form and C's goto will typically just get compiled as an unconditional jump (possibly with whatever stack adjustment is required, if the implementation makes use of a stack).
call/cc is the identity function with the return point and its argument reversed.
Name:
Anonymous2011-10-28 15:28
How can I make this better?
#include <stdio.h>
void main(int i){
char *a[]={"fizz\n","%d\n","%d\n"},*b[]={"fizz","",""};
for(;i<101;i++)
(i%5!=0)?printf(a[i%3],i):printf("%sbuzz\n",b[i%3]);}
>>70
C newbie can't do fizzbuzz with less than four conditionals.
Name:
sage2011-10-28 21:06
ever tried nesting the ternary operator ? I tried and it reminded me of Lisp and all the fancy functional languages that are frequently discussed in places such as this one by you expert programmer people really i'm just a teenager