News for hackers. Stuff that matters.
Re:Nymph: A slightly different version of C by taspeotis on Friday August 18, 2017 @10:09AM (#15046300)
It seems like the compiler allocates memory a lot, and is very optimistic in assuming a) the allocation will succeed and b) strings won't exceed 999 characters plus a null terminator.

https://github.com/roecrew/nymph/blob/master/nymph/example/n...

Re:Nymph: A slightly different version of C by user982 on Friday August 18, 2017 @10:19AM (#15046388)
Seeing how many variables are declared and used like

  int *myDictLen = malloc(sizeof(int));
  *myDictLen = 0;
I strongly suspect that the author is basically unaware of the & address operator. I would suggest that learning C syntax is a prerequisite to improving it.
Re:Nymph: A slightly different version of C by qwertzuiop on Friday August 18, 2017 @11:46AM (#15047194)
Why is declaration wrong? I am in process of learning C, and I don't see anything wrong.
Re:Nymph: A slightly different version of C by sqeaky on Friday August 18, 2017 @11:52AM (#15047259)
You shouldn't new or malloc unless you need to. The more you allocate the more you leak.

Just stack/automatically allocate the resource and take the address with & then pass the pointer around. Because the data is automatically cleaned up you know you won't have any leaks (and certain whole other classes of bugs).

EDIT - Consider:

    int myDictLen = 0;
    int* myDictLenPtr = &myDictLen;

    /* now you can pass around the pointer myDictLenPtr 
       to functions that can used an int* and it will be
       available in this scope and automatically cleaned 
       up for you. */
Re:Nymph: A slightly different version of C by pavlov on Friday August 18, 2017 @11:54AM (#15047279)
If a function takes an argument of type pointer-to-int, you can simply pass a reference to an int variable on the stack with "&myInt". The code in question seems to be using heap allocation just to get a pointer-to-int, which makes one suspect that the author doesn't know about the & operator.
Re:Nymph: A slightly different version of C by green7ea on Friday August 18, 2017 @11:55AM (#15047287)
There is nothing wrong with the syntax itself. Its simply that it's usually preferable to allocate variables on the stack. To do this, you would do:

int var_a = 5;

and use &var_a when you want to acess that variable as a pointer within that scope. Not only is this more efficient, it is much easier to read.

Re:Nymph: A slightly different version of C by nymph1324 on Friday August 18, 2017 @03:43PM (#15049149)
I am aware of that actually....
Re:Nymph: A slightly different version of C by CyberDildonics on Friday August 18, 2017 @08:52PM (#15050908)
Are you aware that malloc() is slow and doing all these tiny allocations is probably the biggest bottleneck in your program?
Re:Nymph: A slightly different version of C by slaymaker1907 on Friday August 18, 2017 @10:57AM (#15046741)
To be fair, C has a bunch of weird things with its syntax like the comma separator commonly used with for loops.
Re:Nymph: A slightly different version of C by hypervis0r on Friday August 18, 2017 @11:01AM (#15046785)
You can't really write a compiler if you don't know all the "weird things" of the language.
Re:Nymph: A slightly different version of C by emeraldd on Friday August 18, 2017 @11:57AM (#15047308)
Sure you can, it just won't be "right." It depends on your use case and target audience if you care about "right" vs "functional." I'd say anyone who wants to really understand how programming works, should write at least one toy compiler/interpreter. It's interesting the kinds of insights you can pickup trying to pull that off.
Re:Nymph: A slightly different version of C by kd0amg on Friday August 18, 2017 @12:07PM (#15047393)
Getting back to this particular case, there's something to be said for the idea of learning C before trying to replace C. C certainly isn't a flawless language, but now it's hard to have much faith that OP knows it well enough to understand its flaws.
Re:Nymph: A slightly different version of C by jwdunne on Friday August 18, 2017 @01:32PM (#15048128)
Is this intended to replace C? I don't see anything that suggests that's what this project is about.

All I see is "C with different syntax". That could easily be a challenging side project whilst learning compilers / language design.

I've always found changing things up a useful means of practice. I wanted to learn how HTTP servers worked. I wanted to learn more Lisp. I implemented it in Common Lisp. I learned a lot.

Re:Nymph: A slightly different version of C by emeraldd on Friday August 18, 2017 @05:13PM (#15049772)
As a point of reference, implementing a broken, partially complete, and definitely error filled version of Scheme on C is how I finally wrapped my head around Lisp. I'd been running into that one for a long time before figuring out.
Re:Nymph: A slightly different version of C by kazinator on Friday August 18, 2017 @01:47PM (#15048240)
The comma operator has more uses than that. One of them is to introduce some needed side effect in a sequence of definitions, without introducing a statement (out of esthetics, or C90 compatibility concerns):

  {
    int x = (side_effect(), initializing_expr());
    int y = x + 42;
From C99 onward, this could be:

  {
    side_effect();
    int x = initializing_expr();
    int y = x + 2;
We use the comma operator in for loops because it has places in its syntax which take one expression. This limitation can arise in other contexts, like some macro MAC(E) where E must be a single expression. If want to to have two sequenced effects in there, we can use MAC((eff1, eff2)).
Re:Nymph: A slightly different version of C by revelation on Friday August 18, 2017 @11:22AM (#15046987)
Oh my god, what is that. I guess the .xcodeproj was a bad sign after all.