by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Mar 03 2017 15:52
    @dom96 banned @Octopoda7
  • Feb 12 2017 23:57
    @dom96 banned @zzz125
  • Dec 23 2016 19:43
    @dom96 banned @Izrab
Kaushal Modi
@kaushalmodi
PMunch: That's awesome!
Thanks! I think on the TOML repo, you can request listing parsetoml as 0.5.0 compliant parser
The readme needs to be updated.. still says "Currently it supports v0.4.0 of the TOML specification."
Brent Pedersen
@brentp
anyone have an example of setting the version in a .nimble file from a version defined in the source of the project so I don't need to update the value in 2 places?
Matt Haggard
@iffy
Can I test if a tuple has a key?
Kaushal Modi
@kaushalmodi
@iffy Interesting, I never had to find that out. But now I am curious too.
From IRC (bridge bot)
@FromIRC
<Araq> when compiles(tup.maKey)
Kaushal Modi
@kaushalmodi
Araq: awesome! thanks
type
  Person = tuple
    name: string
    age: int
let person: Person = ("Peter", 30)
echo compiles(person.age) # true
echo compiles(person.foo) # false
Matt Haggard
@iffy
Thanks!
Kaushal Modi
@kaushalmodi
works for compiles(person[0]) and so on.. too
wondering.. how to get number of fields in a tuple
From IRC (bridge bot)
@FromIRC
<TheLemonMan> you can also use a concept (I think)
Kaushal Modi
@kaushalmodi
I've yet to get into concepts
From IRC (bridge bot)
@FromIRC
<TheLemonMan> I've sent more than 100 PRs, nice
Kaushal Modi
@kaushalmodi
TheLemonMan +1
Araq: still tinkering with that compiles snippet ..
type
  Person = tuple
    name: string
    age: int
let person: Person = ("Peter", 30)
echo $compiles(person.age) & "\t| using tuple type name: " & $compiles(Person.age)
echo $compiles(person.foo) & "\t| using tuple type name: " & $compiles(Person.foo)       # invalid field
echo $compiles(person[0])  & "\t| using tuple type name: " & $compiles(Person[0])
echo $compiles(person[1])  & "\t| using tuple type name: " & $compiles(Person[1])
echo $compiles(person[2])  & "\t| using tuple type name: " & $compiles(Person[2])     # invalid field.. tuple has only 2 fields
that outputs:
true    | using tuple type name: true
false    | using tuple type name: false
true    | using tuple type name: false
true    | using tuple type name: false
false    | using tuple type name: false
so "by name" reference outcome is the same whether I use the tuple type or tuple var
but the field index reference works correctly only with tuple var
Ray Imber
@rayman22201
Hey look, another new language that has a bunch of "innovative" features that Nim has had forever : Kit Programming Language https://news.ycombinator.com/item?id=18023598
Vindaar
@Vindaar
@kaushalmodi number of fields in tuple -> typetraits.arity, so for your example type(person).arity
Kaushal Modi
@kaushalmodi
@Vindaar Cool! thanks
any comment about why Person[0] doesn't work? should it work?
Vindaar
@Vindaar
If I'm not mistaken there was something specific about tuples and indexing by integer
From IRC (bridge bot)
@FromIRC
<Araq> the index must be a constant
Kaushal Modi
@kaushalmodi
It is a constant in that example above
Vindaar
@Vindaar
Oh, I only just realized that you're trying to access the field of the type and not of the specific instance in the latter part. No idea if that should work.
Kaushal Modi
@kaushalmodi
but TupleType.FieldName works..
we are just check if a field exists.. doing type.field is meaningless otherwise
Vindaar
@Vindaar
Well, the compilation error for that is Error: no generic parameters allowed for Person, which sort of makes sense I guess, since it's the same syntax you'd use for generics
Kaushal Modi
@kaushalmodi
hmm, makes sense
so it just happens that the square brackets are generics syntax, else it would have worked
are purely numerical generics possible?
I mean, can a type be just a number?
From IRC (bridge bot)
@FromIRC
<TheLemonMan> static[T] to the rescue
Kaushal Modi
@kaushalmodi
@Vindaar On the flip side, just Person.age (from that above example) error too nim_src_YckhwY.nim(8, 12) Error: type mismatch: got <type int>
but echo compiles(Person.age) returns true
as expected
TheLemonMan: I didn't understand how static[T] can be used here
From IRC (bridge bot)
@FromIRC
<TheLemonMan> you asked "I mean, can a type be just a number"
Vindaar
@Vindaar
Person.age simply returns the type of Person. So the error in your case is that you're doing something with it that doesn't work for a type (I guess you just removed the compiles around it?)
of age in Person I meant
So if you import typetraits it should now echo int
Kaushal Modi
@kaushalmodi
TheLemonMan: ah, OK. I meant something like Option[123] would never be valid, right?
@Vindaar ah, OK to you too :)
so the problem is that the generic parsing kicks on, on seeing Person[0] instead of returing the type of Person[0]
Vindaar
@Vindaar

what TheLemonMan was referring to is

type
  Person2[N: static[int]] = tuple
    name: string
    ages: array[N, int]

let person2: Person2[2] = ("Peter", [1, 2])
echo person2

so yes, soemthing like that is allowed