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

Pages: 1-4041-

Useful feature for next version of C

Name: Anonymous 2009-07-26 20:31

A ->= operator, and possibly .=, which would make it easier to go through linked lists and other such structures with lots of pointers. Instead of writing

p = p -> next;

it can now be

p ->= next;

or, if you're working with binary trees, instead of


while(t && t->v != i)
 if(t->v < i)
  t = t -> l;
 else
  t = t -> r;


it becomes


while(t && t->v != i)
 t ->= (t->v < i) ? l : r;


I'm working on a C-like compiler and I thought this would be a good idea.

Name: Anonymous 2009-07-26 20:36

hmmm, i'm not sure what i think about this.
it seems like a good idea, but it also seems a little clumsy looking

Name: Anonymous 2009-07-26 20:45

#define NEXT(p, next) (p) = (p)->next

Name: Anonymous 2009-07-26 21:13

Correct me if I'm wrong, but you can do this in C++ by overloading operator->=

Name: Anonymous 2009-07-26 21:20

OMFG IT WOULD COMPLETELY ELIMINATE TWO CHARACTERS PER LINE!  THINK OF THE MILLIONS OF DOLLARS THAT COULD BE SAVED IN MAN-HOURS ONCE THIS CHANGE IS IMPLEMENTED!

Name: Anonymous 2009-07-26 21:22

Referential transparency. Higher order functions. Lazy evaluation.

Name: Anonymous 2009-07-26 21:27

>>6
I smirked

Name: Anonymous 2009-07-26 21:30

>>6
U MENA LIEK HASKAL

Name: Anonymous 2009-07-26 21:39

>>4
I think you can only overload operators that already exist.

Name: Anonymous 2009-07-26 21:41

>>1
I don't like it. But that's my opinion.

Name: Anonymous 2009-07-26 21:42

>>5
I hate how they have +=, -=, *= and even >>= but not a ->= or a .= operator. At least make it consistent...

Name: Anonymous 2009-07-26 21:43

Useful feature for next version of C
Classes

Name: Anonymous 2009-07-26 21:50

>>12
that's called sepples.
it's also called SUPREME ENTERPRISE FAGGOTRY

Name: Anonymous 2009-07-26 21:55

>>13
If Bjarne had stopped at classes, C++ would probably be bearable

Name: Anonymous 2009-07-26 21:56

Useful feature for next version of C
Monads

Name: Anonymous 2009-07-26 22:47

My C Wishlist
* Type Inference
* Lambda's
* First Class Functions & Continuations
* Lexical Scoping
* Indentation-based Syntax

Name: Anonymous 2009-07-27 0:47

>>1
Make a front-end that compiles to C or use LLVM, it would probably be the least effort.
>>16
C is C for a reason, it's a low level language and a programmer can easily envision the code that will be (native) generated by the compiler to some degree. Continuations, lambda's (and closures) do complicate the simplicity of a low/mid level language.

If you want them, why not use Haskell, Lisp or Scheme?

Short list and my idea of how hard it would be to implement them:
- Type inferrence cannot be emulated easily, it needs to be build early on in the compiler front-end.
- Lambda's, probably not too hard, it's just a function pointer and an associated environment(when closures are involved). C coders can emulate this to some extent, but it's a lot nastier than it would be if you had native support for it.
- First class functions: you can already pass pointers to functional code, but that doesn't save state/environment, so you'd have to pass the state/environment in some way.
- Continuations: the cost of implementing true continuations in Scheme is great. You need a spaghetti stack for this, or you need to do a lot of stack copying, which is very costly. A C programmer can emulate them by using implementation dependent OS routines and assembly-written routines, however the (memory/time) costs are great and that makes them less practical for common use.
- (Added my own), a true condition system like Common Lisp's: *Nix and Windows both offer more rudimentary ways to implement this, such as signals(*Nix) and SEH(Structured Exception Handling - Windows), both of these rudimentary mechanisms offer enough power to be able to build a real condition system on top of them(An example: in CL, you can signal a condition(think of it as an exception), and define local(or not local) ways to handle the condition, you can decide how and when you want to unwind the stack(if at all), and you can define handling strategies in upper levels, and once the handling is decided, the code can continue running off where it left, with the error fixed. This is better than the C++ exception based system, as you can decide exactly when and how to handle, and don't have to unwind the stack unless you need to.). The only problem with signals and SEH is that most programmers don't always exploit their true strength in such ways, simply because they may not realize it.

- Lexical Scoping: C already has static scoping, but not as powerful as what Lisp and Scheme offer. Lisp has both dynamic and static scoping, while Scheme only has static scoping. Static scoping leads to clean and clear code, and dynamic scoping allows simplifying some code and solving certain important practical problems, I usually try to avoid having many, if at all, global variables in C, but Lisp's "global variables" are much more clean and powerful (and can be safe too, if the usage is right), which convienced me that there are ways to do "global variables" right.

I'd like to be able to use some of these things in C, but at the same time I believe C is C for a reason, and complicating it in such ways would make it no longer be C, but a different language, in which case, why not just go to D or make your own language?

Name: Anonymous 2009-07-27 2:30

OP could just learn how the fucking language works!

C/C++ isn't your toy language.. if you want something to hold your hand go back to python, java, or c#.

Adding an operator is NOT trivial language wide... just overload one yourself or make a bloody macro

#define ASSIGN_TO_FROM(d,s) d=d->s

Name: Anonymous 2009-07-27 14:03

>>17
I think YHBT

Name: Anonymous 2009-07-27 14:18

>>19
Pointer Error: It should be pointing to >>18

>>17
I realize I could implement these manually and so I was only being half serious. Mostly I was wanting Scheme, but called C so that people would let me use it

Name: Anonymous 2009-07-27 14:30

>>20
Compilation to C is an option, but I don't think anybody can claim the generated C code is maintainable or usable for  purposes other than just processing it further and/or compiling it.

Name: Anonymous 2009-07-27 14:37

hax my anus

Name: Anonymous 2009-07-27 14:45

hdx my anus

Name: Anonymous 2009-07-27 14:48

cdr my car

Name: Anonymous 2009-07-27 14:51

YOU WOULDN'T STEAL A CDR

Name: Anonymous 2009-07-27 14:51

>>24
cdar?

Name: Anonymous 2009-07-27 14:59

>>26
yes

Name: Anonymous 2009-07-27 15:14

(let ((C call-with-current-continuation))
  (apply (lambda (x y) (x y))
         (map ((lambda (r) ((C C) (lambda (s)
                                    (r (lambda l (apply (s s) l))))))
               (lambda (f) (lambda (l)
                             (if (null? l)
                                 C
                                 (lambda (k) (display (car l)) ((f (cdr l))
                                                                (C k)))))))
              '((#\H #\v #\space #\o #\space #\e #\d #\y #\u #\space #\i #\p #\t #\d #\y #\?)
                (#\a #\e #\y #\u #\r #\a #\space #\o #\r #\s #\c #\space #\o #\a #\space #\newline)))))

Name: Anonymous 2009-07-27 17:26

>>28
Is that some CPS style?!

Here's my inflexible attempt at it, in plain old CL, without call/cc:


(princ
 ((lambda (x)
    (concatenate 'string (mapcan #'list (first x) (second x))))
  '((#\H #\v #\  #\o #\   #\e #\d #\y #\u #\   #\i #\p #\t #\d #\y #\?)
    (#\a #\e #\y #\u #\r #\a #\   #\o #\r #\s #\c #\  #\o #\a #\   #\newline))))

Name: Anonymous 2009-07-27 21:24

>>25
This might surprise you, >>25, but I am a man of African origins and stealing both cars and cudders runs in my veins.

Name: Anonymous 2009-07-27 21:48

(list->string (reverse (letrec-syntax ((zip (syntax-rules ()
                                              ((_ (a) (b) exp) (cons b (cons a exp)))
                                              ((_ (a b ...) (c d ...)) (zip (b ...) (d ...) (list c a)))
                                              ((_ (a b ...) (c d ...) exp) (zip (b ...) (d ...) (cons c (cons a exp)))))))
                         (zip (#\H #\v #\space #\o #\space #\e #\d #\y #\u #\space #\I #\P #\t #\d #\y)
                              (#\a #\e #\y #\u #\r #\a #\space #\o #\r #\S #\C #\space #\o #\a #\?)))))

Name: Anonymous 2009-07-27 22:26

How would .= work?

struct DESU {
   struct DESU a;
}b;

b .= a;

This is the only way I can think that it would work, for all other purposes it would be worthless, wouldn't it be?

Name: Anonymous 2009-07-27 22:49

>>1
that makes it unreadable as hell
you don't put macros in macros, too.

Name: Anonymous 2009-07-27 23:23

>>33
YO DAWG, WE...etc etc etc

Name: Anonymous 2009-07-27 23:32

>>32
It works like PHP's .=

Just kidding. See en.wikipedia.org/wiki/Linked_list

Name: Anonymous 2009-07-28 1:57

>>35
Hi FrozenVoid!  How's your spam compression game coming?

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !frozEn/KIg 2009-07-28 2:07

>>36 Since i have the monopoly on providing links to wikipedia,i can tell you,that >>35 is a lousy impostor.



__________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
Velox Et Astrum gamedev forum: http://etastrum.phpbb3now.com
Writing is not a profession but a vocation of unhappiness. I don't think an artist can ever be happy.

Name: Anonymous 2009-07-28 14:32

>>35

I still don't see it. Actually, will the code in >>32 even compile? Can a struct have a recursive definition? I can see this working in Java, but not in C. I understand linked lists it's just that a .= b; is supposed to expand to a = a.b;. I fail to see a case where this would be permissible. Could someone enlighten me? It would be like having a *= for pointers, so that a *= b; expands to a = *(a + b);. The type system doesn't permit such an action. I understand ->=, but a->b is already syntactic sugar for (*a).b. Should syntactic sugar have syntactic sugar?

Name: Anonymous 2009-07-28 17:42

>>33
you don't put macros in macros, too.
This is what Ctards actually think.
In languages supporting real macros, you can have macros which write macros for you.

Name: Anonymous 2009-07-28 17:43

>>39
I don't write macros that write macros, I have other macros that do that.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !frozEn/KIg 2009-07-28 17:45

I use macros within macros. It helps reduce clutter and can be manipulated easily. e.g.
#define MAXBUF 1000
#define NMAX MAXBUF*8


_________________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
Velox Et Astrum gamedev forum: http://etastrum.phpbb3now.com
We've arranged a civilization in which most crucial elements profoundly depend on science and technology. We have also arranged things so that almost no one understands science and technology. This is a prescription for disaster. We might get away with it for awhile, but sooner or later this combustible mixture of ignorance and power is going to blow up in our faces.

Name: Anonymous 2009-07-28 18:25

>>41
* sees what FV calls macros
* throws up

Name: Anonymous 2009-07-28 18:39

>>42
I don't think it has to have parameters to be called a macro, dude. The throwing up and the confusion are normal reactions to prolonged FV exposure, though.

Name: Anonymous 2009-07-28 23:22

>>39
Name one.

Name: Anonymous 2009-07-28 23:23

Common Lisp

Name: Anonymous 2009-07-28 23:49

>>1

Or you could, you know, write out a few more letters and make it not look retarded as hell?

Also, who unbanned Frozenvoid?

Name: Anonymous 2009-07-29 0:17

>>29

(princ
 ((lambda (x)
    (concatenate 'string (multiple-value-call #'mapcan #'list (values-list x))))
  '((#\H #\v #\  #\o #\   #\e #\d #\y #\u #\   #\i #\p #\t #\d #\y #\?)
    (#\a #\e #\y #\u #\r  #\a #\  #\o #\r #\s  #\c #\  #\o #\a #\  #\newline))))

Made it more generic, m-v-c + values-list now let us have a variable list of arguments to mapcan/mapcar.
OT: m-v-c is how APPLY is actually implemented on some implementations, such a lovely special operator.

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