nimpylib icon indicating copy to clipboard operation
nimpylib copied to clipboard

Built-in functions porting progress

Open Yardanico opened this issue 7 years ago • 3 comments

  • [x] abs()
  • [x] all()
  • [x] any()
  • [ ] ascii()
  • [x] bin()
  • [x] bool() note: called toBool in pylib
  • [ ] ~~breakpoint()~~ Not really possible
  • [ ] bytearray()
  • [ ] bytes()
  • [ ] callable()
  • [x] chr()
  • [ ] classmethod()
  • [ ] compile()
  • [ ] complex()
  • [ ] delattr()
  • [ ] dict()
  • [ ] dir()
  • [x] divmod()
  • [x] enumerate()
  • [ ] ~~eval()~~ Can't be implemented
  • [ ] ~~exec()~~ Can't be implemented
  • [x] filter()
  • [x] float() note: it's called toFloat in pylib
  • [ ] format()
  • [ ] frozenset()
  • [ ] getattr()
  • [ ] ~~globals()~~ Can't be implemented
  • [ ] hasattr()
  • [ ] hash()
  • [ ] help()
  • [x] hex()
  • [x] id() currently uses unsafeAddr, maybe we can use something else?
  • [x] input()
  • [x] int() note: it's called toInt in pylib
  • [x] isinstance()
  • [x] issubclass()
  • [x] iter()
  • [ ] len()
  • [x] list()
  • [ ] ~~locals()~~ Can't be implemented
  • [x] map()
  • [x] max()
  • [ ] memoryview()
  • [x] min()
  • [ ] next()
  • [ ] object()
  • [x] oct()
  • [x] open()
  • [x] ord()
  • [ ] pow()
  • [x] print()
  • [ ] property()
  • [x] range()
  • [ ] repr()
  • [ ] reversed()
  • [ ] round()
  • [ ] set()
  • [ ] setattr()
  • [ ] slice()
  • [ ] sorted()
  • [ ] staticmethod()
  • [x] str()
  • [x] sum()
  • [ ] super()
  • [ ] tuple()
  • [ ] type()
  • [ ] vars()
  • [ ] zip()
  • [ ] __import__()

Yardanico avatar Jul 14 '18 18:07 Yardanico

Beware: some of these procedures are not yet pushed to the repo.

Yardanico avatar Jul 14 '18 18:07 Yardanico

Yay! :grinning::+1:

juancarlospaco avatar Jul 15 '18 17:07 juancarlospaco

About the unticked python's function or class First, there are some of these functions that can be easily implemented:

  1. slice() can be by system.countup()
  2. ascii() can be implemented by the help of unicode.Rune's proc (I have made it alreadly)
  3. vars() can be by system.fieldPairs for object and tuple

Next, I 'd say that some of these functions are alreadly implememented by nim itself:

  1. round(x[,n]) in std/math
  2. proc sorted[T](a: openArray[T]; cmp: proc (x, y: T): int; order = SortOrder.Ascending): seq)[T] {.effectsOf: cmp.} in std/algorithm
  3. reversed[T](a: openArray[T]): seq[T] in std/algorithm
  4. zip[S,T](s1:openArray[S];s2:openArray[T]): seq[(S,T]) in std/sequtils
  5. len() for set, array, seq and so on

Then, there are still some of them having behaviors that are similar but not the same a bit:

  1. locals() : in Nim it's a static view. And when in the global scope, it's always empty.
  2. type() : in Nim it's a alias of typeof(), and it can only be used to get something's type , not to create a new type (class)

Finally here is a suggestion:
filter[T](s: openArray[T]; pred: proc (x: T): bool {.closure.}): seq[T] is already in std/algorithm

litlighilit avatar Dec 11 '22 10:12 litlighilit