Re: Some nim builtin libs not doing enough error checking?

2019-01-12 Thread wizzardx
I focused on "does not exist" here, but it could be any other error reported by 
C/the OS that results in a nil result - eg, IO/hardware error, permissions 
error reading the dir, etc.


Some nim builtin libs not doing enough error checking?

2019-01-11 Thread wizzardx
eg, this code:


import os

for p in walkDir("/tmpX"):
echo p
echo "Hello"


Run

If the directory /tmpX does not exist, then control flow just passes on to 
after the loop, rather than raising an exception about "directory not found".

In the nim code os.nim, for 0.19.2, around line 866, there's a call to opendir, 
and then logic proceeds if the returned pointer is not nil (ie, there wasn't an 
error.

But there's no branch in that code that handles the nil condition, gets the C 
error, raises, etc.

It's possible to eg, make a PR which adds the C error check, and then raises an 
exception. But that would break existing systems that depend on walkDir's 
current permissiveness. Also, with Nim 1.0 being just around the corner.

I'm picking on walkDir here, but I have seen this in some other places.

Would it be more correct to eg, update documentation for walkDir to state that 
by design it's not intended to? Similar to how eg, removeDir is documented as 
not raising an exception if the directory never existed originally?


Re: Equivalent of dir() in python

2018-09-01 Thread wizzardx
I've learned a bit more since then (now also on last chapter of Nim in Action. 
Templates and Macros are also starting to make more sense).

Also a bit of a better idea of the fine line between where metaprogramming vs 
actual compiler internals lie, where you can and can't cross the two.

Probably you'd need to make a nim compiler plugin (this is how "locals()" is 
implemented). I think this concept is similar to rust's "syntax extensions".

Relevant previous forum thread on the subject (it's not really documented 
anywhere that I can see as a type of Nim metaprogramming):

[https://forum.nim-lang.org/t/1220](https://forum.nim-lang.org/t/1220)

So for instance, it's 
_[probably](https://forum.nim-lang.org/postActivity.xml#probably) possible to 
crossreference this:

compiler/plugins/locals.nim

Alongside the nimsuggest source code (included in Nim github repo)

And add something like these new plugins, to get something a bit more pythonish:

compiler/plugins/globals.nim compiler/plugins/dir.nim


Re: Equivalent of dir() in python

2018-08-30 Thread wizzardx
Is it possible to use metaprogramming to iterate through all of the available 
procs, and then return them as a list or tuple at runtime?

I think this is how both "locals()" and "repr()" already work in Nim. 


Re: Using the MEGA API

2018-08-30 Thread wizzardx
I'm not sure, but you may be able to achieve this (overriding virtual C++ 
functions) by some ugly emission of raw c++ code.

Here's an example:

[https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-importcpp-pragma](https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-importcpp-pragma)


Re: is there computer algebra system module?

2018-08-30 Thread wizzardx
Sounds cool. Add an issue over to the "needed packages" repo?

[https://github.com/nim-lang/needed-libraries](https://github.com/nim-lang/needed-libraries)


Re: Question regarding parallel_counts.nim from Nim in Action

2018-08-30 Thread wizzardx
Thanks, good to know!

Can we document spawn as having blocking behavior in that case? 


Question regarding parallel_counts.nim from Nim in Action

2018-08-29 Thread wizzardx
As per this file referred to in Chapter 6:

[https://github.com/dom96/nim-in-action-code/blob/master/Chapter6/WikipediaStats/parallel_counts.nim](https://github.com/dom96/nim-in-action-code/blob/master/Chapter6/WikipediaStats/parallel_counts.nim)

Isn't this kind of a race between how fast the disk can read the file, and how 
fast the CPU threads can process it?

eg, with a huge file, slow CPUs, fast IO, low RAM, the system can run out of 
ram because of too many separate threads being in the middle of the 
parseChunk() function, where each thread is hanging onto at least 1_000_000 
bytes of ram?

Or does something special happen (eg, "spawn" function starts blocking) when 
the # of spawned functions reaches MaxThreadPoolSize (256).


Re: Is there any way to create template with await?

2018-03-23 Thread wizzardx
Nim's 'async' macro rewrites the code so that it becomes iterable/etc where 
needed.

[https://nim-lang.org/docs/asyncdispatch.html#17](https://nim-lang.org/docs/asyncdispatch.html#17)

I think what Dom's doing here is giving a slightly desugared version of what 
the 'async' macro would normally do for your code. 


Re: Partial casing is foo_bar

2018-01-23 Thread wizzardx
Thanks, interesting alias syntax!

Also, there's some nice syntax for aliasing over in the issue tracker over here:

[https://github.com/nim-lang/Nim/issues/7090](https://github.com/nim-lang/Nim/issues/7090)

Edit: Have also requested that this be added to the Nim Cookbook:

[https://github.com/btbytes/nim-cookbook/issues/21](https://github.com/btbytes/nim-cookbook/issues/21)


Re: Nim Syntax ''Skins''

2018-01-22 Thread wizzardx
How about Racket-style #lang pragmas?

That way you can use any syntax or semantics you want in a given module, so 
long as your "lang" definition contains a parser 


Re: Partial casing is foo_bar

2018-01-22 Thread wizzardx
Besides OpenGL, there's also SDL2, which can't be faithfully represented 
because of partial casing, eg SdlError enum, vs say SDL_Error.

On the other hand, recently working with Ada, I see there's a lot of case 
insensitivity there too, which is a point in it's favor:

[https://en.wikibooks.org/wiki/Ada_Programming/Lexical_elements#Character_set](https://en.wikibooks.org/wiki/Ada_Programming/Lexical_elements#Character_set)

On the gripping hand, I'd really like to be able to eg, go through C tutorials 
on C libs, without having to - while going through those tuts and docs - also 
rename a lot of identifiers over to the renamed Nim versions that wrap those 
lower level C libraries.


VS Code integration is great

2018-01-22 Thread wizzardx
Hi there!

I've tried getting minimal IDE-type setups working for a lot of langs recently.

They more or less work, but don't have working features like "jump to 
definition" (especially into the standard lib), or are otherwise really hard to 
get working and configured right.

This is helped a lot by the fact that the nim stdlib is also in Nim, and very 
easy to read and understand, vs many other langs, where things can get far more 
cryptic in the stdlibs.

Just a shoutout to nimsuggest and it's great integration with VS Code.


Borrowing ideas from Ada (2012)?

2018-01-22 Thread wizzardx
Have opened a ticket on github with a related feature request:

[https://github.com/nim-lang/Nim/issues/7122](https://github.com/nim-lang/Nim/issues/7122)

But also bringing it up on the forum for possible further discussion.

Anyhow, I'm a big "high integrity"-type fanboy. I don't program in Ada (yet), 
but I'm really enthusiastic about it.

Nim already seems to borrow many features from Ada (I think Araq's even 
mentioned this before, I think it was something like providing Ada, but being 
blamed for C's shortcomings).

Anyhow, I figure it's a really nice idea to scavenge some ideas off of Ada 
2012. Partly to help bring that kind of set of secure (or more importantly, 
high integrity/reliability) practices more to the mainstream (also, some 
further distinguishing of Nim vs other more mainstream langs than Ada).

We probably won't ever get to the level of "SPARK"-type static analysis, but 
base Ada alone, is I think leagues ahead of just about every other lang.

(implied here, also an ideas like making "contract programming" libs, like 
NimContracts, part of the stdlib, or having floating-point range types, etc), 
as well as being able to promote Nim as having a focus on security/high 
integrity.

Thoughts on this? 


Re: Best way for function aliases

2018-01-16 Thread wizzardx
Looks like this also works (might not have worked then, but it works with 
current Nim devel):


proc foo(x: int) = echo x
template bar(x) = echo x
bar 10


And similarly (for future readers), this kind of usage also works, for 
non-procs:


var a = 200
var b = addr a
b[] = 300
echo a


Though it's not entirely safe.


Re: How to get real time of parallel code

2017-10-30 Thread wizzardx
https://github.com/nim-lang/Nim/issues


Re: How to get real time of parallel code

2017-10-29 Thread wizzardx
I've made an issue request for this on the Nim Cookbook project 

@jzakiya; open a feature request ticket against the nim github repo?


Re: How to track down missing nimcache/read.o ?

2017-10-29 Thread wizzardx
Deleting the nimcache directory also works.

"There are 2 hard problems in computer science: cache invalidation, naming 
things, and off-by-1 errors." \- secretGeek


Re: How do you keep your motivation on your open-source projects

2017-10-29 Thread wizzardx
Just working on things when I feel like it or need to, for solving some other 
problem that I'm excited or motivated about 


Re: Send data structures between threads?

2017-10-29 Thread wizzardx
I don't understand it, but nice  Have added an issue on the Nim Cookbook for 
this to be added there.


Re: possible compiler bug with generics?

2017-10-28 Thread wizzardx
Or at least, I think that's probably a fundamental underlying model.

There's a lot of higher level clever things that Nim does before getting to 
separate C files, I think separate .c units is just an optimisation not a 
restriction, but that it did to some extent shape how the Nim compiler logic 
worked during development.

Nim probably just needs to be taught to be able to treat "let x = 5.Foo" and 
"let x = 5.toFoo" the same way, rather the base case of how separate C 
compilation works. In which case, types.o in the not-working version still 
wouldn't export any (proc) symbols, but lib.c would know that it was dealing 
with an int.

I think it might be something like a small bug or limit on the type inference, 
where technically it could infer something, but it's not yet able to.

Well, basically I think it's something like there's no huge formally unifying 
theory behind how the entire Nim lang semantics should work for a given lang 
ver (eg, something like a lang report spec made by committee); but rather it's 
something that's defined by what the most recent compiler supports, as well as 
Araqs insights over time. 


Re: possible compiler bug with generics?

2017-10-28 Thread wizzardx
I checked things a bit.

I _think_ it's an artifact of Nim code compiling each nim file into a separate 
.c file. After that point the regular C toolchain takes over.

c gets compiled to .so, and then .so files get compiled to the final binary.

Anyhow, at the .so level, there's some symbols exported; mainly for things like 
global variables, or for (non-generic) functions. But nothing like C 
structures. The .so files are already 99% machine code by that point.

So anyhow, in the working version, the .so file for types.nim has got an 
exported link symbol for "toFoo" that takes an int and returns an int.

In the not-working symbol, there's no link symbols that can be exported. ie, 
there's no useful .so file that could be produced directly from types.nim

So anyhow, that kind of C compilation semantic probably gets reflected in how 
Nim does parsing of things like generics, to be able to compile the .nim files 
separately to C, and then link them together again to get to the final binary.

I think it's something like that, anyhow.

Probably the compiler could be updated so that it follows rules that aren't 
constrained by the C compiling and linking process. But that would probably 
also make compilation take a lot longer; something like whole-program type 
inference would need to take place, or something like that.


Re: testing private methods in external module

2017-10-28 Thread wizzardx
I'm pretty clueless in general with Nim, but don't you always put curley brace 
pragmas just before the equals sign, rather than in some other place? (I can't 
think of any exceptions to this in the code I've seen so far).


Re: VS Code: Compiled Nim program

2017-10-28 Thread wizzardx
I work with VS code for Nim, but how I (and I'm guessing a lot of Nim users 
work) usually compile and execute the apps in a separate command-line (ie, what 
editor or IDE you're using doesn't affect your dev and testing).

Just a total random thumbsuck, but it may be some interaction with "nimsuggest" 
that can cause this problem? Try disabling the Nim-specific addons in VS Code 
(or just disabling nimsuggest) and see if that makes a difference?


Re: Nim discord server

2017-10-28 Thread wizzardx
Hmm - what segment of the Nim community would this be for?

I haven't used it, but isn't Discord mainly for gamers (basically, text message 
or voice)? So that's also assuming that people are online at the exact same 
time, while playing a given multiplayer game.

What kind of advantage would this provide over how the Nim community currently 
uses IRC? 


Re: Wrapping cpp type with integer parameters

2017-10-28 Thread wizzardx
I'm pretty clueless here, but just some 2c.

How well is this handled in other non-C++ langs or tools which do have interop 
with C++?

Some examples that come to mind: D lang, Python with pybind11, and SWIG.

And a couple of other usual things - providing a C extern function from C++ 
that somehow gets the job done, or using the Nim "emit" statement at strategic 
places to get needed C++ interop code. Or reversing things - write the app 
mainly in C++, but take advantage of Nim lang as far as possible (eg, CPP 
codegen from Nim (or direct .so/dll files), which then gets pulled into the C++ 
compilation, but only where that works, and use native C++ for the rest - eg 
I'm reminded about how Chucklefish uses Rust for most of their code for 
Spellbound, but then uses console-specific code like C++ to call into the Rust 
logic).

It sounds like none of these would work (based on comments in this thread), but 
I'm mainly curious about why none of these are feasible 


Re: possible compiler bug with generics?

2017-10-28 Thread wizzardx
I think that's just normal Nim behavior, right?

If module A imports module B, and module B imports module C, then module A 
won't automatically see everything that B imported that was able to let B 
compile?

You could probably solve the probly by either:

1\. Import types.nim in bug.nim, to bring Foo into scope.

2\. Use an export statement in lib.nim, for Foo

It's probably also possible for tne Nim compiler to automatically do some kind 
of export/import so that bug.nim can - while importing lib.nim, also "see" the 
required types from "types.nim"; at least to the extent so that bug.nim could 
typecheck correctly.


Re: Winim Excel

2017-10-28 Thread wizzardx
Congrats on finding that.

I'm not sure, but I get several results if I google for "Component Object Model 
Excel.Application"

Another way to put it - I think you'll have some success if you try to make a 
Windows app (eg: VB.net, VBscript, C#, etc, whatever you know best) that uses 
the "Excel.Application" COM API directly, and then see if that maps back well 
to the Nim library. 


Re: Is this use of Nim locks correct?

2017-10-26 Thread wizzardx
Ah, also a reminder - try nimgrep in addition to regular grep:

[https://nim-lang.org/docs/nimgrep.html](https://nim-lang.org/docs/nimgrep.html)

Nim's style insensitivity means that you may miss a few useful things if you 
just use the regular grep.


Re: Nim Wiki stuff

2017-10-25 Thread wizzardx
Cool . Also at your suggestion I made a pull request for adding the Wiki the 
main website.

With some luck that should show up at the bottom of this page sometime in the 
near future:

[https://nim-lang.org/community.html](https://nim-lang.org/community.html)


Re: Is this use of Nim locks correct?

2017-10-25 Thread wizzardx
I think "memoryReadBarrier" was just an example.

One way you can get more info is to do a git clone of the source code, and then 
grep for where memoryReadBarrier occurs, for instance:


$ grep memoryReadBarrier * -R
doc/manual/locking.txt:  memoryReadBarrier()


Grepping for "atomicRead" shows a few more examples, over in the tests:


$ grep atomicRead * -R
doc/manual/locking.txt:  template atomicRead(x): untyped =
doc/manual/locking.txt:  echo atomicRead(atomicCounter)
tests/parallel/tguard1.nim:template atomicRead(L, x): untyped =
tests/parallel/tguard1.nim:  echo(atomicRead(c.L, c.i))
tests/parallel/tguard2.nim:template atomicRead(L, x): untyped =
tests/parallel/tguard2.nim:  echo(atomicRead(c.L, c.i))


Nim also seems to have some kind of concept of volatile, too, if I grep for 
that:


david@david-pc:~/dev/learning/nim/github/Nim$ grep volatile * -R | grep -v 
'c'
lib/pure/volatile.nim:template volatileStore*[T](dest: ptr T, val: T) =
lib/pure/volatile.nim:{.emit: ["*((", type(dest[]), " volatile*)(", 
dest, ")) = ", val, ";"].}
lib/system/threads.nim:var x {.volatile.}: pointer
lib/js/jsffi.nim:"volatile", "null", "true", "false"]


In particular, this builtin lib may be interesting to you:

lib/pure/volatile.nim

And here's one main lib I can find at the moment that deals with atomics:

lib/system/atomics.nim


Re: using if expressions

2017-10-25 Thread wizzardx
I ninja-edited my earlier post with some other details.

I'm not sure why, but 'case expressions' and 'if expressions' are designed a 
bit differently to each other, and are documented that way.

I think perhaps it's something like "things that can be an expression" are 
mainly some specific special cases, and "case expressions" got more love than 
"if expressions".

Try submitting a feature request over on the issue tracker perhaps?

[https://github.com/nim-lang/nim/issues](https://github.com/nim-lang/nim/issues)


Re: using if expressions

2017-10-25 Thread wizzardx
>From some playing around with it, I think that the entire case structure needs 
>to be an expression, rather than a mix of statements and expressions.

eg, an echo statement anywhere in there seems to cause problems.

However, something that does seem to work is to call a function which returns 
the expected type; and then inside that function, do the echoing.

I think though that what you're trying to do should be valid, according to the 
docs:

[https://nim-lang.org/docs/manual.html#statements-and-expressions-case-expression](https://nim-lang.org/docs/manual.html#statements-and-expressions-case-expression)

Not sure, but I think it's a compiler bug.


Re: I enjoy seeing the nimble package updates

2017-10-25 Thread wizzardx
I got pointed to our existing Wiki; I didn't know that it existed 

So anyhow; I've made a new forum topic for that over here:

[https://forum.nim-lang.org/t/3282](https://forum.nim-lang.org/t/3282)


Re: progress while binding libxl

2017-10-25 Thread wizzardx
May be better to try to make your own really basic wrapper in the meanwhile, 
and put that in github 

For some ideas and inspiration you can watch the "c2nim" section of Araq's 2 
hour Nim Workshop YouTube vid 


Re: I enjoy seeing the nimble package updates

2017-10-25 Thread wizzardx
Ah thanks, that looks really nice, too!.


Re: I enjoy seeing the nimble package updates

2017-10-25 Thread wizzardx
Not sure how practical it is or if it's against Github's TOS in some ways, but 
here's one example of something that would be easy to scrape and parse:

[https://raw.githubusercontent.com/bpr/vla/master/vla.nimble](https://raw.githubusercontent.com/bpr/vla/master/vla.nimble)


I enjoy seeing the nimble package updates

2017-10-25 Thread wizzardx
Mainly over in the in the packages.json file, over here:

[https://github.com/nim-lang/packages/commits/master](https://github.com/nim-lang/packages/commits/master)

It's really fun watching what kinds of packages get added in there over time.

I check it out every couple of days, and then usually check out the links to 
the project home page.

That might make for something like a nice main page feed too. Or especially if 
there's some way to also keep track of version bumps by automatically following 
the github repos and seeing when the version number in the ".nimble" file 
changes, and then adding that to a main page feed.

In the same way; it's also fun to watch other lang's "package releases" 
changelogs; eg for PyPi main page:

[https://pypi.python.org/pypi](https://pypi.python.org/pypi)


Re: progress while binding libxl

2017-10-22 Thread wizzardx
@alfrednewman

It might be possible to wrap a Python XLS library in Nim?.

It's an approach I'm considering for some python libs I'm having trouble 
porting to Nim due to my lack of low-level C coding ability - eg Pyglet.

It's not entirely unprecedented, Haskell also wraps some awesome python libs to 
bring some of that magic into their ecosystem:

[https://hackage.haskell.org/package/matplotlib](https://hackage.haskell.org/package/matplotlib)


Re: object problem - undeclared identifier

2017-10-22 Thread wizzardx
Here's one nice use of methods vs procs in Nim that I've seen recently:

[https://vladar4.github.io/nimgame2/tut101_bounce.html](https://vladar4.github.io/nimgame2/tut101_bounce.html)


Re: nim-cookbook

2017-10-20 Thread wizzardx
Update: Looks like I can't delete the wiki directly!

(I think this is for good reason; on a case by case basis - so that eg, rogue 
admins can't take their community hostage or whatever).

Have made an official request to wikia to delete it, opening ticket #349088 on 
their system.

It should hopefully be deleted within 2 business days.

Wikia wiki is currently over here, but should hopefully disappear soon:

[http://nim-lang.wikia.com/wiki/The_Nim_programming_language_Wiki](http://nim-lang.wikia.com/wiki/The_Nim_programming_language_Wiki)


Re: nim-cookbook

2017-10-20 Thread wizzardx
Hmm, then I'll put that on hold for now 

Already created the wikia, but I'll see if I can nuke it.


Re: nim-cookbook

2017-10-20 Thread wizzardx
Ideally: One of the core devs puts a mediawiki instance under the nim-lang.org 
server.

But failing that, Wikia is a very nice place for starting and maintaining 
community wikis, eg:

[http://bleach.wikia.com/wiki/Bleach_Wiki](http://bleach.wikia.com/wiki/Bleach_Wiki)

Edit: Should I take initiative and start it myself?

I don't want to steal anyone's thunder, or do something that's too 
controvercial amongst the Nim community 


Re: Beginner question about nil access

2017-10-20 Thread wizzardx
Some things I _really_ like here about nim vs many other proglangs.

1\. Nil access actually segfaults, rather than silent or undefined behavior.

2\. You get a really awesome stack trace.

I use "not nil" wherever I can, too, but it's kind of a losing battle, since 
all the other code wants nillable types, so you have to add a lot of 
converters/checking code/etc, which kinda defeats the purpose 


Re: What should next Araq's live stream be about?

2017-10-20 Thread wizzardx
Really really cool idea; I'm planning to watch all the livestreams; at least 
once they hit youtube . I've subscribed to both Araq's and Dom's channels on 
there!

Is there a suitable place for adding suggestions for future live streaming 
subjects?

Is that best brought up in IRC perhaps? (have never been on there; I'm more of 
a forum dweller).


Re: nim-cookbook

2017-10-20 Thread wizzardx
Any chance we could do this on a regular wiki, rather than needing to make 
github pull requests?

eg like this:

[https://www.renpy.org/wiki/renpy/doc/cookbook/Cookbook](https://www.renpy.org/wiki/renpy/doc/cookbook/Cookbook)
 .


Re: Pragma for temporarily making strict identifier names?

2017-10-18 Thread wizzardx
Thanks for the replies!

What I've also done in the past to bypass Nim's naming rules - eg, where and 
how you can use underscores, is to look for a utf8 unicode symbol that looks 
almost exactly like what I want to use.

eg in a direct transliteration of some python code:


self._private = 123


Nim doesn't like the leading _ in _private, but I can search on a page like 
this:

[http://csbruce.com/software/utf-8.html](http://csbruce.com/software/utf-8.html)

And then eg, use an identifier like this (for instance), which Nim is fine with:


self.⎯private = 123


Where ⎯ comes from the "u23A0" section.

So I could also - probably - as a horrible hack, use a replacement for the Q 
symbol, eg:


const ԚUIT_SDL = ...


where the "Q" symbol comes from the "u0500" section.

...

If the symbols are too close/confusing for typing out later, I can also use 
alternative symbols, for eg naming like this:


const ԾUIT_SDL = ...


Pretty awful hack though . 


Re: Pragma for temporarily making strict identifier names?

2017-10-17 Thread wizzardx
Wrappers so far are mainly for my own private testing use, rather than for 
something to publish 

Basically, going through the lazyfoo tuts, but transliterating as closely as 
possible from the original C over to Nim

eg, code snippets like these, from the C version of chapter 3:

[http://lazyfoo.net/tutorials/SDL/03_event_driven_programming/index.php](http://lazyfoo.net/tutorials/SDL/03_event_driven_programming/index.php)


//User requests quit
if( e.type == SDL_QUIT )
{
quit = true;
}


And


//Quit SDL subsystems
SDL_Quit();


I'd be trying to write directly like this in Nim:


# User requests quit
if e.`type` == SDL_QUIT:
quit = true


And


# Quit SDL subsystems
SDL_Quit()


Mainly it means that for my direct translation from C to Nim, that one snippet 
needs to change to this for me:


# User requests quit
if e.`type` == SDL_QUIT_CONSTANT:
quit = true


Was mainly wondering if there's a way to not need to do that kind of renaming 
while doing direct transliterations from other languages to Nim 


Re: Safe sdl2 wrapper library?

2017-10-17 Thread wizzardx
I got a bit stuck here.

It's hard to eg, create a RAII-type object in a function, and then pass that to 
a caller.

Nim wants to destroy the previous object and then make a new object.

Haven't really worked with it, but I think what's missing is some kind of move 
semantic. I think that's under dev? (have seen something like an =sink operator 
under github).

Basically; would like to do a Nim library similar to what this C++ library 
supports in terms of RAII, automated tidy-up, and also flexible passing around 
of RAII objects without triggering their destructors unnecessarily:

[https://github.com/libSDL2pp/libSDL2pp](https://github.com/libSDL2pp/libSDL2pp)

At the moment I need to eg, set a property called "disableDestructor" to true 
before returning a RAII-type object from a function, and then setting 
"disableDestructor" back to false again afterwards.

Comments?


Pragma for temporarily making strict identifier names?

2017-10-17 Thread wizzardx
Use case:

I'm trying to make a really basic sdl2 library from scratch, that maps directly 
to the C version.

The C code declares this function:

Sdl_Quit

But there's also this constant:

SDL_QUIT

Due to Nim's style-insensitivity, I can't have both of these identifiers as is. 
eg they both start with a caps S, and otherwise look the same in terms of 
identifier name to the Nim compiler

Possible to get some kind of pragma to use strict styling rather than flexible 
styling?

eg something like this;

{.push strictStyle.}

proc Sdl_Quit() = ...

const SDL_QUIT = ...

{.pop strictStyle.}

Then those identifiers only ever get used in the code if you use the exact same 
naming, rather than eg, nim thinking the two are the same identifier.

Comments?

PS: My current temporary workaround is to name the SDL_QUIT constant, 
SDL_QUIT_CONST. But that means that I can't get a direct 1-1 mapping between C 
code and nim code (for instance).

Or is there perhaps some existing method, eg stropping, which already handles 
this kind of problem?


Re: Safe sdl2 wrapper library?

2017-10-06 Thread wizzardx
Thanks for the idea though.

I'm going through lazyfoo tuts, and making a high level but also really safe 
wrapper while I'm about it.

The high level wrapper builds on top of the really safe low level wrapper I was 
working on before.

So eg, my lazyfoo chapter 01 port looks like this:


import ../../my_sdl2_libs/high_level_sdl2

const
  SCREEN_WIDTH = 640
  SCREEN_HEIGHT = 480
  WHITE = (0xFF, 0xFF, 0xFF)

proc main =
  var sdl2_context = initSdl2Context(initvideo=true)
  
  var window = sdl2_context.createWindow(title="SDL Tutorial",
 width=SCREEN_WIDTH,
 height=SCREEN_HEIGHT,
 windowShown=true)
  var screenSurface = window.getSurface()
  screenSurface.fillRect(color=WHITE)
  window.updateSurface()
  sdl2Context.delay(2.0)

main()


There's no pointers or references used there, all of those are wrapper objects 
with built-in Nim destructors, so they also automatically tidy their resources 
when they go out of scope.

Also not using OR-based flags, but rather bool arguments.

Nim's named and optional arguments are really awesome, you don't need to use 
builder patterns nearly as much as in some other langs. 


Re: "Cross-platform C" target for Nim?

2017-10-06 Thread wizzardx
Have been trying for a while but haven't yet been able to get niminst working 
for me  (I'll keep trying to figure it out later)

But I think the secret is actually over here during the process of installing 
Nim from github:

git clone --depth 1 
[https://github.com/nim-lang/csources.git](https://github.com/nim-lang/csources.git)

Over there is c source code - generated by nim, for an earlier version of the 
Nim compiler.

And that C source code comes in basically a huge number of permutations of OS 
and Architecture.

Basically, 10 OS for 10 CPUs would contain 100 sets of C source code, that get 
bundled up over in csources.git

So basically, the trick is to just compile your nim project for all the 
combinations of OS and CPU that you want to target .

I thought there might be something like a single set of canonical source code, 
with a huge number of #ifdefs or something, but I guess this way works better 
for Nim and the codegen backends 

Cool!


Re: Safe sdl2 wrapper library?

2017-10-06 Thread wizzardx
After much gnashing of teeth and wailing, and I guess a few hours of random 
hacking too.

I'm guessing it's probably just a lot easier to work against Vladar's nimgame2 
most of the time for a high level SDL2 wrapper, there's already a huge amount 
of quality work put into it:

[https://vladar4.github.io/nimgame2](https://vladar4.github.io/nimgame2)/

(still, it's fun to hack for the sake of hacking and getting practice, even if 
what you're working on right now is ultimately useless  )


Re: General hacking in the Nim ecosystem.

2017-10-06 Thread wizzardx
@Udiknedormin lol yeah.

Going further, "Nim is the new Python, Rust is the new C"


Re: General hacking in the Nim ecosystem.

2017-10-05 Thread wizzardx
Probably comes down to people taking initiative. But not in ways that are 
counter to how the core devs need things to be run.

I guess I'd mainly want to ask @core devs - what their opinion is on - I guess 
the general idea of "online community" management around Nim, and how they'd 
want to grow that kind of thing.

I don't mean things like Codes of Conduct, I mean more - I guess soft - human 
type things where people feel more welcome and comfortable and involved and 
stuff.

That kind of thing I think is also very important for smaller online 
communities.

(I have some small experience in some unrelated online community).

Well, this is just my general uninformed opinion. Hope the core devs find some 
use for my 2c on this subject 


Re: General hacking in the Nim ecosystem.

2017-10-05 Thread wizzardx
To start with...

Is there some kind of way to make a forum poll?

(eg: this is a phpbb feature I've frequently used in the past, for this kind of 
thing)


Re: General hacking in the Nim ecosystem.

2017-10-05 Thread wizzardx
Is there perhaps some kind of Nim equivalent to "Find something Rusty to work 
on"?

[https://www.rustaceans.org/findwork/starters](https://www.rustaceans.org/findwork/starters)


General hacking in the Nim ecosystem.

2017-10-05 Thread wizzardx
Hi there!

I saw recently in the (really awesome) "nim survey" for 2017, that there's a 
bunch of ecosystem things that people are requesting:

[https://nim-lang.org/blog/2017/10/01/community-survey-results-2017.html](https://nim-lang.org/blog/2017/10/01/community-survey-results-2017.html)

eg, top of the list seems to be something like a python requests-like library

(as a random idea, Rust Lang already has over here, which could be liberally 
borrowed from, if not outright wrapped using the C FFI for a very early 
version):

[https://docs.rs/requests/0.0.30/requests](https://docs.rs/requests/0.0.30/requests)/

)

And then there's also the Google Summer of Code 2016 application over here, 
which lists some different projects:

[https://github.com/nim-lang/Nim/wiki/GSoC-2016-Ideas](https://github.com/nim-lang/Nim/wiki/GSoC-2016-Ideas)

Is there any kind of place (eg wiki), where these kinds of things can be 
maintained and tracked?

(eg, something like ongoing progress/who is busy on what, who is mentoring, 
etc, and then kept up to date with eg, what's been chatted about on IRC or on 
the forums, that kind of thing).

Well, I guess it depends on how many volunteer hackers there are floating 
around with some free time to kill, who're interested in that kind of project.

Random eg, I see that PMunch might be interested 

[https://www.reddit.com/r/nim/comments/73ul3g/nim_community_survey_2017_results](https://www.reddit.com/r/nim/comments/73ul3g/nim_community_survey_2017_results)/

Also, whether there might still be some kind of mentor/mentee relationship, 
outside of an official GSoC event. Guess you might call it NSoC for Nim Summer 
of Code instead, if it doesn't make GSoC; and then do that informally

Well, just random stuff I'm curious about.

Might also be an interesting exercise to poll about just how many people might 
be interested in some kind of slightly more coordinated effort to check off 
some of those projects 


Re: Safe sdl2 wrapper library?

2017-10-05 Thread wizzardx
In terms of "proper" high level SDL2; I'd probably want to do something like 
re-implement the rust SDL2 wrapper. What I mainly like about that is not that 
it's Rust, but that it's entirely safe by default.

Probably wouldn't go as far as making a Result[T] type and returning that; 
Idiomatic general Nim I think is more about taking advantage of the GC, as well 
as throwing exceptions. Someone else can wrap things in Result[T] if they like 
that. 


Re: Python-like with, context managers, and the RAII pattern

2017-10-05 Thread wizzardx
@Benjaminel: I'm trying to emulate the Python "with" style, which is more 
general-purpose than just files. I think that "using" in C# is similar, to take 
any given resource for a block, and then auto-close it for you at the end of 
that block.

@Others:

Thanks for the replies so far! So, I another question 

1\. Can you update the macro so that it can work without an "as X" clause?

eg, something like this:


echo "I'm anywhere on the filesystem"

with changeDir("/tmp/x"):
   echo "I am now under /tmp"

echo "I'm back to where I was before"


Which then would expand to something along these lines:


echo "I'm anywhere on the filesystem"

var private_x = changeDir("/tmp/x")
var private_y = my_enter(private_x)

try:
   echo "I am now under /tmp"
finally:
   my_exit(private_y)

echo "I'm back to where I was before"


Would like to be able to have a "with" macro that supports both forms, based on 
whether there is an "as" clause.

Thanks! 


"Cross-platform C" target for Nim?

2017-10-05 Thread wizzardx
Hi there.

Generated C Nim code usually targets specific a specific OS and CPU combination 
with it's C gen backend.

But the tarball for Nim itself (also written in Nim), is cross-platform, and 
doesn't require a specific CPU or OS to be present.

Is there a way to tell the Nim compiler to output cross-platform C, in a 
similar sense to how Nim itself is distributed as a single tarball?


Re: Safe sdl2 wrapper library?

2017-10-04 Thread wizzardx
I've started playing with a port of pygame_sdl2 over to Nim. Probably won't go 
anywhere, but I'm having fun with it 

[https://github.com/renpy/pygame_sdl2](https://github.com/renpy/pygame_sdl2)

And occasionally jumping between that and trying to re-implement some really 
basic parts of Ren'Py into.

Eventually something like cocos2d-nim might be fun to work on .

Mainly it's an excuse for me to play with Nim; studying books or tutorials is 
more boring and makes me sleepy 

That said; what's wrong with nim-lang/graphics as it is?

I don't see any open issues on it. Also, no README, so I'm not sure what it's 
trying to achieve exactly compared to other graphics or game libs that already 
exist?

Edit: I found this documentation:

[https://nim-lang.org/0.11.0/graphics.html](https://nim-lang.org/0.11.0/graphics.html)

Could you perhaps add some issues against the github repo? eg as feature 
requests.


Re: Python-like with, context managers, and the RAII pattern

2017-10-01 Thread wizzardx
Thanks for the replies!


Re: Python-like with, context managers, and the RAII pattern

2017-09-30 Thread wizzardx
Thanks!

So if I understand it correctly, this macro usage in your snippet:


take 3 as f:
echo f


Gets expanded to this:


var f = 3
echo f


How can we change the same macro, so that it desugars over to this instead?


var x = 3
var f = my_enter(x)
try:
f = 3
finally:
my_exit(x)


Where:

1) x is a private variable inside the macro.

2) f is the only variable that gets exported (and then used within the 
statement block), so that the statements in the body can use it.

3) my_enter is a separate function that the user must supply, eg:

eg:


proc my_enter(x: int): int =
  echo "my_enter was called"
  return x


4) my_exit is a separate function that the user must also supply, eg:


proc my_exit(x: int) =
  echo "my_exit was called"



Re: Python-like with, context managers, and the RAII pattern

2017-09-29 Thread wizzardx
Thanks for the replies 

Is it possible to express the "withAs" template as a macro?

So that my example could look like this:


with open("test.txt") as f:
echo f.readLine()


I think it should be possible, since eg nimpylib lets you use this syntax:


class Customer(object):
  """A customer of ABC Bank with a checking account. Customers have the
  following properties:
  Attributes:
  name: A string representing the customer's name.
  balance: A float tracking the current balance of the customer's 
account.
  """


eg, over here:

[https://github.com/Yardanico/nimpylib/blob/master/examples/example2.nim](https://github.com/Yardanico/nimpylib/blob/master/examples/example2.nim)


Python-like context managers and

2017-09-28 Thread wizzardx
Hi there.

I like the Python RAII pattern of "with" statements, alongside context managers.

eg, this is nice:


with open("test.txt") as f:
print f.read()


Closest thing to that I could find was the "withFile" example over in the 
second Nim tut.

So I've tried to adapt that example a bit, and ended up with this:


template withAs(x: typed, y: untyped,
body: untyped): typed =
  var x2 = x
  var y = x2.enter()
  try:
body
  finally:
exit(x2)

proc enter(f: File): File =
echo "Entering context manager"
return f

proc exit(f: File) =
echo "Leaving context manager"
f.close()

open("test.txt").withAs(txt):
  echo txt.readLine()


So when I run that, I get this output:


Entering context manager
HOW ARE YOU GENTLEMEN
Leaving context manager


So it looks like things are working.

Is "withAs" (and context managers) an existing well-known Nim pattern?

Would be nice to be able to eg, do "nim install contextlib", and then have 
"withAs" as well as some other useful things.

Comments? 


Re: Random idea - porting python 3 stdlib to Nim.

2017-09-07 Thread wizzardx
Thanks for those replies!

@evacchi, you're absolutely right; thanks for the reminder re cython.

@Tiberium, I'll probably be using nimpylib a fair amount in the future, maybe 
sending a pull request here and there 


Random idea - porting python 3 stdlib to Nim.

2017-09-06 Thread wizzardx
Just a random brainfart.

Would probably start by taking typeshed static type declarations for python 
builtins.

String would probably be a wrapped unicode/runes string; bytes would be mainly 
native c bytes.

Arbitrary precision int libgmp.

There's already a lot of libs which bring python-like libs etc over to Nim.

Resulting code would be totally none-idiomatic Nim and probably a lot slower.

I'm not volunteering for this; just throwing out a totally random idea.

Pretty terrible idea right? Lol.