Nim as a classic programming language

2021-06-11 Thread Sixte
> `{.prototype(extensible).}` These could also be valid inside the defining > module. Yes but you have submodules then. How to make it explicit in recent Nim, it's not in the language yet. Your syntactic extension looks reasonable. > A general thought: prototypical/exemplary definitions seem to

Nim as a classic programming language

2021-06-02 Thread Sixte
>A required goal if we want to get out of today's whack-a-mole type system >development. ;-) > Whack-a-mole ? Type system ? Really? Imperative languages do offer product types for both datatypes and function types and typechecking via identity. Some coercions, e.g. int8 -> int32, and conversio

Nim as a classic programming language

2021-05-23 Thread Araq
> A DSL for type calculus and transformation rules which produces the compiler > code for type verification and resolution and defines new type > implementations with Nim's existing types as building blocks; is that a pipe > dream or a realistic goal? A required goal if we want to get out of to

Nim as a classic programming language

2021-05-23 Thread bpr
> I'm sorry, but you didn't get the irony here I guess the joke's on me. I couldn't decide if you were serious or not :-)

Nim as a classic programming language

2021-05-23 Thread Sixte
Me:"Well, concepts were newly introduced (Dec 2020), the draft paper had 380+ pages, so give C++ a try, the language will mature soon." > If you read the code at the end of the message you replied to, you'll see a > translation into C++ 20 which compiles with both clang and g++ > (--std==c++20)

Nim as a classic programming language

2021-05-23 Thread bpr
> Well, concepts were newly introduced (Dec 2020), the draft paper had 380+ > pages, so give C++ a try, the language will mature soon. If you read the code at the end of the message you replied to, you'll see a translation into C++ 20 which compiles with both clang and g++ (--std==c++20), and d

Nim as a classic programming language

2021-05-23 Thread gemath
Really interesting, as your comments usually are. I've started diving into type theory and things you, @timothee and others have contributed are part of the reason. A modification proposal: the minimal one-pragma approach is elegant, but let's not break import visibility semantics: the meaning

Nim as a classic programming language

2021-05-23 Thread Sixte
...but we omitted the star at Gstack. This makes the type _extendable_ . Due to the {.prototype.} pragma, the compiler knows that Gstack is a virtual type will be exported. But now, the user programmer could write: * Gstack[U] = Ustack[U] and therefore extend Gstack with a new implementatio

Nim as a classic programming language

2021-05-23 Thread Sixte
> For those who use C++, C++ 20 concepts fail this test as well Well, concepts were newly introduced (Dec 2020), the draft paper had 380+ pages, so give C++ a try, the language will mature soon. > BTW, nice example! I hope you file an issue. IDK. Probably not. The typing world has changed consi

Nim as a classic programming language

2021-05-18 Thread bpr
Reading the [new style concepts RFC](https://github.com/nim-lang/RFCs/issues/168), we see that the first goal is Empower concepts to make generic code type-checkable at declaration time, not only at instantiation time. Run >From that we can draw some hope that th

Nim as a classic programming language

2021-05-18 Thread Araq
It trusts the user.

Nim as a classic programming language

2021-05-18 Thread bpr
The concept is not checked in the procedure body during the declaration, like a regular non generic type would be. That's unfortunate. I wonder if there's a conservative solution to rule out cases like this without making the concepts unusable? For those who use C++, C++ 20 concepts fail this t

Nim as a classic programming language

2021-05-18 Thread margin
> There is nothing to prove really. These annotations override the compiler's > reasonings. Well I mean if an acyclic prameter/type is acyclic, but it's to complex to figuring that out, does the compiler trust the user or is an error issued?

Nim as a classic programming language

2021-05-18 Thread Araq
> What is the strategy for these 5 things, if the compiler can't prove them for > certain situations, is then an error issued or not? There is nothing to prove really. These annotations override the compiler's reasonings.

Nim as a classic programming language

2021-05-18 Thread margin
> Nim's type system, Concepts. Do they provide statical guarantees? Let's see... I find having both generics and templates is too much. Either approach has its advantages.

Nim as a classic programming language

2021-05-18 Thread xigoi
Concepts provide positive guarantees, but not negative guarantees. Nim will still use static duck typing to try to substitute the type, and if it works, cool.

Nim as a classic programming language

2021-05-18 Thread Sixte
Nim's type system, Concepts. Do they give statical guarantees? Let's see... #{.experimental.} type Aclass = concept x x.inum is int Anobj = object fnum : float inum : int Bnobj = object text : string inum : int

Nim as a classic programming language

2021-05-17 Thread bpr
> It doesn't compile, but you get the error report only if the function gets > used really. This is expected behaviour within Nim because Nim resolves > Generics late and ad-hoc, this will say using concrete types when all generic > types are gone. Sure, this is like C++ SFINAE. This is why I s

Nim as a classic programming language

2021-05-17 Thread Sixte
> @juancarlospaco, why the scare quotes around "bugs"? At the very least, the > code in @sixte's first code block that is marked as ill typed, should not > compile. It doesn't compile, but you get the error report only if the function gets used really. This is expected behaviour within Nim beca

Nim as a classic programming language

2021-05-17 Thread margin
> So far there are no plans to go beyond sink/lent/move/cursor/acyclic. I know > these 5 new things can be a bitter pill to swallow but they are opt-in and > also address issues existing since Nim's initial design, not only "memory > safety". To the best of my knowledge the design is reasonably

Nim as a classic programming language

2021-05-17 Thread bpr
> The program compiles and prints the content of the sum type Stype as expected. Terminology nit: Maybe it's just me, but I wouldn't call Stype a "sum type". I reserve that for Rust/Swift enums or OCaml variants. You'd model sum types in today's Nim with object variants. I hope tomorrow's Nim fo

Nim as a classic programming language

2021-05-17 Thread juancarlospaco
Yep, you can write type edgy "bugs" like these on Python and Typescript too.

Nim as a classic programming language

2021-05-17 Thread Sixte
Generics and Nim's type system again, let's see what we have. We have: import typetraits type Atype[T] = object data: T inum: int Btype[T] = object jnum : int data: T Stype[U] = Atype[U] or Btype[U]

Nim as a classic programming language

2021-05-17 Thread Sixte
> also think there's far more benefit to fixing Nim than developing a Nim > inspired C dialect Honestly, the main motivation for the NimC example was to smuggle in an innocent looking typedef [T]; working as a generically defined type through the entire file. The same thing could be done with N

Nim as a classic programming language

2021-05-17 Thread Sixte
> I told you but you won't listen. ;-) You might have told me but perhaps I didn't understand. At least, I learned that actually the LLVM target is not a viable alternative to C. So, please try to explain it again. Especially how to deal with a stackless memory model. . (It is not an accident t

Nim as a classic programming language

2021-05-16 Thread bpr
Did you file issues for this yet? I also think there's far more benefit to fixing Nim than developing a Nim inspired C dialect, but you've got to do what you want.

Nim as a classic programming language

2021-05-16 Thread Araq
> So we can safely conclude that C should not be used as a target language > longer. Oh wait... No, we generate C because it has excellent optimizers... The portability is nice too. But it's closer to Algol than it is to an assembler. The subtle aspects of its spec make the Nim compiler harder

Nim as a classic programming language

2021-05-16 Thread Sixte
> It's 2021 now, C has "volatile" and dozens of subtle concepts. Now you can > argue all of this was required, but the fact is that it is not "simple" > anymore. So we can safely conclude that C should not be used as a target language longer. Oh wait... The basic idea of NimC was not to promot

Nim as a classic programming language

2021-05-16 Thread Araq
> When C came up, it felt pretty intuitive... The stack/heap split was already in Algol and Fortran, but ok, it was intuitive, in the 70ies. It's 2021 now, C has "volatile" and dozens of subtle concepts. Now you can argue all of this was required, but the fact is that it is not "simple" anymore

Nim as a classic programming language

2021-05-16 Thread juancarlospaco
> assembler allows for control flow that C doesn't; an assembler's syntax is > more regular and thus easier than C's, an assembler allows easy access to > overflow flags, an assembler doesn't conflate pointers and arrays, and > finally an assembly language doesn't have very subtle aliasing restr

Nim as a classic programming language

2021-05-16 Thread Sixte
> C is not a portable assembler, the machine code you get out of a C compiler, > while somewhat predictable, isn't more predictable than e.g. Ocaml's machine > code it's less predictable because C has the better optimizers. When C came up, it felt pretty intuitive, producing small binaries and

Nim as a classic programming language

2021-05-16 Thread Sixte
> help us to define what Nim's type system actually is Let's see. type Atype[T] = object data: T inum: int Btype[T] = object data: T iinum : int # Atype and Btype are isomorphic, however they do not have the sa

Nim as a classic programming language

2021-05-14 Thread Araq
> I'll now consider NimC... We simply need better education... C is not a portable assembler, the machine code you get out of a C compiler, while somewhat predictable, isn't more predictable than e.g. Ocaml's machine code -- it's less predictable because C has the better optimizers. Furthermore

Nim as a classic programming language

2021-05-14 Thread Sixte
I have a couple of intentions with this thread (stackless Nim <=> statefule aka "static" Nim, Linear Programming, Call-by-Name in Nim) but letting all these nasty things aside, I'll now consider NimC, not a new C, but a "tainted" or better painted C that brings Core-Nim's memory model and Nim's

Nim as a classic programming language

2021-05-08 Thread Araq
> I hope Nim will not go into the Rust direction. Again... It's a little bit too late for these remarks and fears. We copied the inspiring things that Rust offers, made them work well for Nim's design and called the result `--gc:orc`. And even though you should not praise yourself ... I'm not l

Nim as a classic programming language

2021-05-08 Thread alexeypetrushin
I hope Nim will not go into the Rust direction. I gladly pay x2 and even x4 more memory and CPU cost, just so I don't have to deal with things like Rust. :)

Nim as a classic programming language

2021-05-08 Thread shirleyquirk
i understand the arbitrariness of the choice, and the ugliness of the asymmetry. maybe my lack of understanding is about what the metaphor of 'ownership' represents. In my mind, it represents the locus of control over an objects deletion, as defined through différance with a viewer, which can ke

Nim as a classic programming language

2021-05-08 Thread Sixte
> i'm more familiar with the idea that one of the next or prev refs be owned, > the other a view. Do you prefer the left or the right side? A good doubly linked list implementation should provide two entrypoints, one to each side. Insert and Delete will work identically for both pointers. How

Nim as a classic programming language

2021-05-08 Thread shirleyquirk
> In a doubly linked list, every node inherently has two owners. can you explain this model? it seems to me that multiple ownership is the same as none. i'm more familiar with the idea that one of the next or prev refs be owned, the other a view.

Nim as a classic programming language

2021-05-08 Thread Sixte
Memory safety is a multipolar discipline. Linear type theory describes how ressources move through the program. A "viewer" is part of a triple (Owner,Data,Viewer). We have a sequence : (Owner,Data,None) => (Owner,Data,Viewer) => (Owner,Data,None). As long as the viewer is active, the data alloc

Nim as a classic programming language

2021-05-08 Thread Araq
Can't say I agree, "simplicity" is not a value in itself or else we would all still be writing assembler code. (Yes, assembler is simpler than C, it's not simpler to use, but you focussed on language simplicity.) > When a language decides to add three new keywords, it does not result in > three

Nim as a classic programming language

2021-05-07 Thread hankas
Memory safety is good. If you can make it happen, by all means you should. If you can't, it is okay to have manual memory management. There is nothing wrong with it. Some people tend to think that C/C++ bugs result from its manual memory management. That is not entirely accurate. The occurrence

Nim as a classic programming language

2021-05-07 Thread bpr
Thanks, I spotted the bug now.

Nim as a classic programming language

2021-05-07 Thread Araq
Works for me and the newer version of the document is a complete example, no need for a `resize`.

Nim as a classic programming language

2021-05-07 Thread bpr
> Every type has =destroy but it can be "trivial", like in C++. When I took the code from the destructors manual, added a missing `resize` proc resize[T](x: var myseq[T]) = x.data[x.len] = cast[typeof(x.data)](realloc(x.data, x.len * sizeof(T))) x.cap = x.len

Nim as a classic programming language

2021-05-07 Thread Araq
> What's supposed to happen when you have a sequence of elements that don't > have an =destroy, like ints? Can value types get an implicit no-op =destroy? Every type has `=destroy` but it can be "trivial", like in C++.

Nim as a classic programming language

2021-05-07 Thread bpr
> To the best of my knowledge the design is reasonably complete and the > implementation is catching up. Cool! Quick question about that: in the destructor manual, the _mostly_ complete example (needs 3 line implementation of **resize** ) of defining a myseq calls the `=destroy` on all the elem

Nim as a classic programming language

2021-05-07 Thread Araq
> It seems that Nim is now exploring the ownership ala Rust (sink, lent, move). > I certainly hope Rust lifetime stuff does not creep into Nim. So far there are no plans to go beyond sink/lent/move/cursor/acyclic. I know these 5 new things can be a bitter pill to swallow but they are opt-in and

Nim as a classic programming language

2021-05-07 Thread GamzWithJamz
Even though Nim has lots of GC options, most seem like toys or are for special use cases. Like @Araq mentioned [here](https://forum.nim-lang.org/t/7927#50492), `--gc:orc` changes a lot for Nim's coming evolutions/additions. Simplification of Nim can easily come in the form of better defaults (l

Nim as a classic programming language

2021-05-07 Thread hankas
My ideal language is something like a modern C or a minimalist C++. A language with built-in concurrency library, unicode support, basic OO constructs, generics, intuitive metaprogramming, clean syntax, easy interoperability with C, and performant. Being memory safe is a plus, but I am fine with

Nim as a classic programming language

2021-05-07 Thread Araq
I agree with most of your points, but I mind > Until now, macros can only deal with Nim-parsed code and therefore the Nim > parser is in the way. How is it in the way? You can easily write compile-time parsers that work on a triple quoted string literal and produced NimNodes, see how `strformat

Nim as a classic programming language

2021-05-04 Thread Sixte
Nim is in the line of classic programming languages: FORTRAN, Pascal, C. Nim represents a minimal (if not THE minimal) closure over C's memory model. * FORTRAN did not use a stack for variables at all, because any of these were placed in global memory. Recursion did not work of course, but the