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

Pages: 1-4041-8081-

I like C but not its syntax

Name: Anonymous 2014-12-02 12:11

Why hasn't anyone made C that doesn't look like dogshit?

Name: Anonymous 2014-12-02 12:18

Just use s-exps. Should be easy e.g. with Racket. I mean, there is already L++.

Name: Anonymous 2014-12-02 12:23

(def pointer_compare (-> (location1 void *) (location2 void *) int)
(cond
((< location1 location2) ~1)
((> location1 location2) 1)
(t 0)))

Name: Anonymous 2014-12-02 12:28

(def string_hash (-> (string void *) (unsigned int))
(def result (: int) 5381)
(def p (: (unsigned char *)))
(set! p ((cast unsigned char *) string))
(while (!= (@ p) '\0')
(set! result (+ (<< result 5)
(result)
(@ p)))
(++ p))
(result))

Name: Anonymous 2014-12-02 12:30

I'm sorry, I meant

(def string_hash (-> (string void *) (unsigned int))
(def result (: int) 5381)
(def p (: (unsigned char *)))
(set! p ((cast unsigned char *) string))
(while (!= (@ p) '\0')
(set! result (+ (<< result 5)
(result)
(@ p)))
(++ p))
result)

Name: Anonymous 2014-12-02 12:30

C looks fine

Name: Anonymous 2014-12-02 12:34

>>6
...in this thread.

Name: Anonymous 2014-12-02 12:38

creat

Name: Anonymous 2014-12-02 14:04

>>8
Blame Unix, not C. I guess it comes up Thompson either way and even he regrets it.

Name: Anonymous 2014-12-02 16:33

Unfortunately there's no way to use a Lisp as a GC-less systems language. The syntax is tied to the evaluation model, which depends on being able to perform arbitrary allocations in the construction of a value. Even if you implemented a new dialect designed for manual memory management, there would simply be no way around this problem.

Name: Anonymous 2014-12-02 16:53

>>10
There's a way to use Lisp syntax for C.

Name: Anonymous 2014-12-02 16:56

>>11
No, unfortunately, that's just impossible.

Name: Anonymous 2014-12-02 17:04

>>12
Whatever you say. Just don't visit this page, it might shatter your worldview:

https://bitbucket.org/ktg/l

Name: Anonymous 2014-12-02 17:13

The goofy syntax is not even the worst problem with C, by far. It's the way it straddles the huge gulf between "portable assembler" and "fast applications language" and isn't especially good at either of those roles. A language trying to replace C should aim for one side of that chasm or the other, and do a better job there.

Name: Anonymous 2014-12-02 17:28

>>8-9
DOS has create
Checkmate unix niggers.

Name: Anonymous 2014-12-02 17:49

>>14
The syntax is the only problem with C. Read >>1.

Name: Anonymous 2014-12-02 20:18

>>16
The syntax is the only non-problem with C.

Name: Anonymous 2014-12-02 21:04

>>17
No, the syntax is definitely one of the problems with C.

Name: Anonymous 2014-12-03 4:49

creat my anus

Name: Anonymous 2014-12-03 13:02

>>18
The syntax is as good as programming language syntax will ever get. You won't improve on it, because there's no improvement to be had.

Name: Anonymous 2014-12-03 13:08

>>20
Try trolling more gently next time, OK?

Name: Anonymous 2014-12-03 13:44

There are some inconsistencies with the syntax; however, the syntax itself is simple and (for the most part) consistent.

Name: Anonymous 2014-12-03 14:01

>>22
Also ugly and stupid. Why does the return type come before the function name? Why do I have to visually fish the line to get the fucking name of what's being declared?

def func_name(type1 arg1, type2 arg2): ret_type { ...

would be much better.

Name: Anonymous 2014-12-03 14:16

>>22
Another thing that's wrong with C's syntax is that the "pointer" operator at the type level is the same as the "dereference pointer" at the value level. Because of that I always want to throw up when I see C code. These are two fucking opposite operations, who had the idea to denote them with the same (*) sign? Fucking idiots.

Name: Anonymous 2014-12-03 14:20

Also the array syntax is stupid. Why is it int arr[] if it's not an int? It's an array of ints, the [] needs to go to the type, ya incestuous drunken faggots. Hey, it's equivalent to int* arr (at least in function arguments), so why does the * go to the type if the [] goes to the identifier? Fucking disgusting.

Name: Anonymous 2014-12-03 14:27

>>23
What the fuck? No, C is fine as it is.

Name: Anonymous 2014-12-03 14:30

>>26
But its syntax sucks.

Name: Anonymous 2014-12-03 14:55

>>27
The return type before the function type is the least of the concerns about its syntax,

Name: Anonymous 2014-12-03 15:11

>>28
Well why don't you tell us your major concerns about its syntax? Also if it's a small concern, why was this mistake fixed in newer languages like Rust and Go?

Name: Anonymous 2014-12-03 15:40

>>28
Having the return type anywhere else is stupid and doesn't make any sense.

Name: Anonymous 2014-12-03 15:58

>>23
Personally, it looks better with the type before, but it's harder to parse. I'm not sure why they did that. I wouldn't, in a language I made.

Name: Anonymous 2014-12-03 16:08

>>24
It's a mnemonic. But I don't wonder why you don't know it, only a retard would complain about C's syntax.
int **i means that **i is of type int.

>>25
Same for this. int arr[] means that arr[N] is of type int

Hey, it's equivalent to int* arr
Only people that do not understand C syntax use int* arr. This shows something about you.

so why does the * go to the type if the [] goes to the identifier
It does not. Think of int* a, b. b is a int while *a is a int.

I still have to see a real problem about C's syntax in this thread.

Name: Anonymous 2014-12-03 16:12

>>23-25,31
You do not understand C. Naturally you are frustrated and confused by what you do not understand. But, as I know better, I will selflessly go out of my way to enlighten you.

In other languages, you would write the identifier, and then the identifier's type: Foo : Integer, Bar : Map<String, Float>, and word []char. But the syntax for declaring such identifiers is completely different from the syntax for using them in your code, which complicates the language: You must be able to express both the name of the type itself and the way it is used.

In C, there is a different basic rule: You write the type of an expression (the contents of a dereferenced pointer or array, or the return value of a function) and then you write an expression invoking the identifier you are declaring, using exactly the same syntax as you would in normal code. And naturally, the type of that expression is the same type that precedes it in the declaration: The type of *p is int, and therefore you would write int *p. The type of buf[n] is unsigned char, and therefore you would write unsigned char buf[BUFSIZ].

If it were not done this way, C would need additional syntax for each of these types: A special syntax for function types, a special syntax for pointer types, and so on. Reusing what is already there allows the compiler to save precious memory and grammar complexity by simplifying the language. It is the best choice a language designer could have made.

Name: Anonymous 2014-12-03 16:24

>>31
but it's harder to parse
How's that?

Name: Anonymous 2014-12-03 17:18

only a retard would complain about C's syntax.
Didn't read the rest.

Name: Anonymous 2014-12-03 17:33

>>33
Okay, I see some sort of rationale behind C's syntax, but it still doesn't justify the choices made for C. For example, writing the function declaration like

int func_name(...);

would make sense in a pure language, where the expression func_name(...) may indeed be replaced by a value of type int. But it doesn't make sense in C because there are unrestricted implicit side effects everywhere, and a function call is not, as a rule, observationally equivalent to its return value.

Same goes for the other arguments:

1) C wouldn't need a special syntax for function types because it doesn't have function types. It forces you to use (void *) for all function types.

2) C already has special syntax for pointer types, e.g.

[code]typedef int* IntPtr ;

3) C already has an infernally complex grammar. If simplicity was wanted, why not use s-exps? They're much simpler.

Name: Anonymous 2014-12-03 17:40

>>35
You just proven me right.

Name: Anonymous 2014-12-03 18:05

>>37
No. I've just seen that you are a conceited idiot and you present no proofs to the contrary.

Name: Anonymous 2014-12-03 18:09

If you can't argue without calling names you're obviously wrong. That's what "add hominem" means.

Name: Anonymous 2014-12-03 18:19

>>39
Ad hominem

Name: Anonymous 2014-12-03 18:42

>>36
1) C wouldn't need a special syntax for function types because it doesn't have function types. It forces you to use (void *) for all function types.
Wait, what?

typedef int* IntPtr
It's not special syntax.

If simplicity was wanted, why not use s-exps?
Because it would look like shit for C.

Name: Anonymous 2014-12-03 19:02

Okay, OP, here you go. Here's what C might look like with a different syntax and basically no other changes (except fallthrough because fuck that)

function main(argc: Int, argv: [[Char]]) -> Int do
var ch: Int
var stdout_lock: FileLock
setlocale(LC_TYPE, "")
while (ch = getopt(argc, argv, "belnstuv")) != 1 do
case ch of
'b' =>
bflag = nflag = 1
'e' =>
eflag = vflag = 1
'l' =>
lflag = 1
'n' =>
nflag = 1
else
usage()
end case
end while
argv += optind
if lflag then
stdout_lock.l_len = 0
stdout_lock.l_start = 0
stdout_lock.l_type = F_WRLCK
stdout_lock.l_whence = SEEK_SET
if fcntl(STDOUT_FILENO, F_SETLKW, addr_of stdout_lock) == -1 then
err(EXIT_FAILURE, "stdout")
end if
end if

if bflag oror eflag oror nflag oror sflag oror tflag oror vflag then
scanfiles(argv, 1)
else
scanfiles(argv, 0)
end if

if fclose(stdout) then
err(1, "stdout")
end if

exit(rval)
end function


Rewritten from https://github.com/freebsd/freebsd/blob/master/bin/cat/cat.c

Name: Anonymous 2014-12-03 19:21

>>41
C doesn't have function types, it has only pointers to functions which all have the same useless type (void *).

Oh and C in sexps would be awesome.

Name: Anonymous 2014-12-03 19:43

>>42
What happened to the semicolons?

Name: Anonymous 2014-12-03 20:14

>>43
which all have the same useless type (void *)
This is false, void * is a data pointer, not a function pointer. You can't point to a function with void *.

How are pointers to functions useless?

Name: Anonymous 2014-12-03 22:46

Name: Anonymous 2014-12-03 22:49

>>46
install gentoo

Name: Anonymous 2014-12-03 23:04

Try using ALGOL.

Name: Anonymous 2014-12-04 0:28

>>42
There's a good reason we don't write C like that: The English-style keywords are slower and use more memory than punctuation. Maybe you should stick to talking about dynamic languages where that kind of performance hit is deemed acceptable.

Name: Anonymous 2014-12-04 3:05

>>49
I think that English keywords to delimit structural blocks is as stupid as anyone else, but is performance really the way to make that argument? The difference between the resources used by each parser itself should be, like, nothing, compared to later compilation phases, and even less if you avoid the yacc/lex bloat.

Name: Anonymous 2014-12-04 6:56

>>49
No they don't. C is a compiled language, there are no English-style keywords in compiled C code.

Name: Anonymous 2014-12-04 7:35

>>51

no its interpreted language

POOP ME RONG G! POOP ME RONG!

Name: Anonymous 2014-12-04 8:14

>>52
it's actually a programming language.

Name: Anonymous 2014-12-04 12:02

>>53
And a very crappy one at that. No generics, extremely shitty macros, etc.

Name: Anonymous 2014-12-04 12:11

Only generic I need is a bit

Name: Anonymous 2014-12-04 12:12

>>54

Generics can be achieved with function pointers and void *.
Every other language has shitty macros.

Name: Anonymous 2014-12-04 12:17

>>56
Bullshit.

Name: Anonymous 2014-12-04 16:47

I will make a Sexpr-C that translates to C as a gift to >>1 even though I like C's syntax.
Just wait for it.

Name: Anonymous 2014-12-04 17:41

>>58
That would be great, thanks. C could really benefit from a s-exp syntax.

Name: Anonymous 2014-12-04 20:06

>>59
Okay. Here is what the new syntax will look like.

(preprocessor-include-file "stdio.h")

(int main (function-of (int argc) ((pointer-to (pointer-to 'char) argv))))
(begin)
(for-loop)
(begin)
(if-statement (< argc 2))
(begin)
(function-call puts "y")
(end)
(else-statement)
(begin)
(for-loop (int i 1) (< i argc) (++ i))
(begin)
(if-statement (> i 1))
(begin)
(function-call putchar #\space)
(end)
(function-call printf "%s" (array-get argv i))
(end)
(function-call putchar #\n)
(end)
(end)
(end)

Name: Anonymous 2014-12-04 20:18

>>60
I was actually wondering what should I use instead of * for pointers.

Name: Anonymous 2014-12-04 20:25

>>60

How would this look?

char *(*(*(**lol[]) (long double p[2], size_t n)) (int))[10] = { NULL, NULL };
printf("%d\n", (int) (sizeof lol / sizeof lol[0]));

Name: Anonymous 2014-12-04 20:28

>>61
maybe (* (+ argv i))

Name: Anonymous 2014-12-04 20:45

>>61
If you want to be serious and not a little shit like >>60? Something like:
(: p (ref int))
(deref p)

Name: Anonymous 2014-12-05 1:34

>>60
what's the point of using s-exprs if you're using being and end
this is a joke, right

Name: Anonymous 2014-12-05 1:45

>>56
you're mission: check these dub

Name: Anonymous 2014-12-05 2:46

>>65
Programming is never a joke.

Name: Anonymous 2014-12-05 3:49

>>66
Nice bro xD

Name: Anonymous 2014-12-05 5:42

>>54
Generics don't belong in C. Use void* and cast.

Name: Anonymous 2014-12-05 10:20

>>69
In other words, C is useless.

Name: Anonymous 2014-12-05 10:40

>>70
Generics are hardly perfect.

http://en.wikipedia.org/wiki/Covariance_and_contravariance_%28computer_science%29#Covariant_arrays_in_Java_and_C.23

As discussed above, covariant arrays leads to problem with writes into the array. Java and C# deals with this by marking each array object with a type when it is created. Each time a value is stored into an array, the compiler inserts a check that the run-time type of the value is equal to the run-time type of the array. If there is a mismatch, an ArrayStoreException (or ArrayTypeMismatchException in C#) is thrown:

Runtime checks have no place in C.

Name: Anonymous 2014-12-05 10:42

>>71
No, it is subtyping that is highly imperfect. Not generics.

Name: Anonymous 2014-12-05 10:46

No, it is subtyping that is highly imperfect and requires runtime tag checks all the time.

is what I meant.

Name: Anonymous 2014-12-05 10:51

>>72
Wow, you're right. I'm sorry. Please use a term that doesn't remind me of java in the future. But still, although clean generics that don't break with no inheritance could be done in C, you end up messing around with casting so much it isn't that big of a deal to have a data structure consisting of a single type of values and to always cast when you access them. You can't take types too seriously in C. There's too much freedom.

Name: Anonymous 2014-12-05 10:57

>>74
So you're saying that C is like a Lisp without GC then, OK. Greenspun's tenth rule QED.

Name: Anonymous 2014-12-05 11:01

>>75
Greenspun's tenth rule is false. QED.

Name: Huskellfaggot 2014-12-05 11:04

>>75
I would say that lisp is an assembly language. Its core is simply and expressive, yet you can build things of near infinite complexity on top of it. C is the same way, except built upon a differnt assembly language. A real one instead of the lambda calculus. Also, much harder to build skyscrapers in.

Name: Anonymous 2014-12-05 11:57

>>77
assembly language
Assembly language is fast. LITHP is slow. Other than that, you're right. It is much harder to built skyscrapers in.

Name: Anonymous 2014-12-05 12:32

>>74
Since when does the word "generics" associate with Java? Educate yourself:

https://www.princeton.edu/~achaney/tmve/wiki100k/docs/Generic_programming.html

Name: Anonymous 2014-12-05 12:34

Generic programming pioneer Alexander Stepanov wrote: "Generic programming is about abstracting and classifying algorithms and data structures. It gets its inspiration from Knuth and not from type theory. Its goal is the incremental construction of systematic catalogs of useful, efficient and abstract algorithms and data structures. Such an undertaking is still a dream."

Name: Anonymous 2014-12-05 21:28

javascript is C with a nicer syntax
also look at asmjs.org

Name: Anonymous 2014-12-05 22:29

>>79
Since Java became popular. I would say expose yourself to industry, but you will eventually. You'll hate it. And then you'll kill yourself.

Name: Anonymous 2014-12-05 22:48

>>82
*presses human liver into your pizza base*

Horrible Industries gone BAD!

*presses eye balls into your can of soup*

Ditto, Jake.

Name: Anonymous 2014-12-05 22:57

I just want a C with first order functions and true closures.

Name: Anonymous 2014-12-05 23:13

>>84
You can do them. It's just not syntactically convenient.

Name: Anonymous 2014-12-06 0:03

>>84
Try Go.

Name: Anonymous 2014-12-06 0:04

>>86
Go is not close to C despite being advertised as so.

Name: Anonymous 2014-12-06 1:01

>>84
That's harder than it sounds. What do you do with closed-over stack space when it's been returned from its owning function, or sent to another thread?

Name: Anonymous 2014-12-06 1:52

>>88
Your anus is harder than it sounds.

Name: Anonymous 2014-12-06 2:45

>>88
Just garbage collect the closure environments and nothing else. What's the problem?

Name: Anonymous 2014-12-06 5:11

>>91
It gets too weird to deal with.

Name: Anonymous 2014-12-06 12:38

>>88
Nice dbus bro xD

Name: Anonymous 2014-12-06 13:31

>>81
Long time no see, Javashit kike!

Name: Anonymous 2014-12-12 17:37

Name: Anonymous 2014-12-12 19:13

>>94
.kfc
Dats racist!

Name: Anonymous 2014-12-14 13:45

I don't know how L++ made getting from Racket to C look so hard.

Name: Anonymous 2014-12-24 17:11

Name: Anonymous 2016-06-08 19:52

>>23
Why does the return type come before the function name?
To match the variable declaration syntax. int x; means "this is a variable that stores a variable of type int". int factorial() { ... } means "this is a function that generates a variable of type int". If you just think of functions as a dynamic counterpart to variables, it makes sense.

Name: Anonymous 2016-06-09 10:20

>>98
Checkem

Name: Anonymous 2016-06-09 17:54

Just use chicken, it compiles to C
sage

Name: Anonymous 2016-06-09 18:01

>>100
chicken
What programming language is this?

Name: Anonymous 2016-06-09 18:08

Name: Remember: it could be worse 2016-06-09 18:33

<function>
<function-head>
<name>minimum</name>
<return-type>numerical/integer</return-type>
<parameters>2</parameters>
<parameter-name>a</parameter-name>
<parameter-type>numerical/integer</parameter-type>
<parameter-name>b</parameter-name>
<parameter-type>numerical/integer</parameter-type>
</function-head>
<function-body>
<condition-statement>
<condition-test>
<less>
<left-operand>
<variable>a</variable>
</left-operand>
<right-operand>
<variable>b</variable>
</right-operand>
</less>
</condition-test>
<condition-true>
<return>
<variable>a</variable>
</return>
</condition-true>
<condition-false>
<!-- nop, fall thru --> <!-- thanks, adam -->
</condition-false>
</condition-statement>
<return>
<variable>b</variable>
</return>
</function-body>
</function>

Name: Anonymous 2016-06-10 9:59

>>103
Stahp!!, this is worse than XML lithp!

Name: Anonymous 2016-06-10 14:41

I like /prog/ but not its posters.

Name: Anonymous 2016-06-11 2:17

>>103
Xml makes c the accpetable lisp

Name: Anonymous 2016-06-12 9:00

>>8
cadr

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