GithubHelp home page GithubHelp logo

nim-in-action-code's Introduction

This repository contains the source code for all the projects developed inside the Nim in Action book.

⚠️ Nim 1.2.0+ is not compatible with some of the Nim in Action examples, use Nim 1.0.6 for the best experience or be ready for compilation errors. See here for more info.

Official book website: https://book.picheta.me

FAQ: https://github.com/dom96/nim-in-action-code/wiki/FAQ

Errata for Nim 1.0: https://deepakg.github.io/nim/2019/09/28/nim-in-action-errata.html

Nim Version Compatibility

Branch v0.17.2 v1.0.6 v1.2.6
master ✔️ ✔️
v1.2.6 ✔️ ✔️

ℹ️ The master branch holds the code that reflects what is in Nim in Action. Other branches contain code modified to work with later versions of Nim.

nim-in-action-code's People

Contributors

dom96 avatar kevinkelley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nim-in-action-code's Issues

not GC-safe

Some of my Nim projects use asyncHttpServer, and I'm always nagged by the requirement for GC safe HTTP handlers, even when not using threads but only async.

Curious to see how this was handled in Jester I turned to your example code, just to find you have the same problem here :)

The example code from chapter 7:

../../../../../home/ico/external/Nim/lib/pure/asyncmacro.nim(267, 31) Warning: 'matchIter' is not GC-safe as it accesses 'db' which is a global using GC'ed memory [GcUnsafe2]

Compiling with --threads:on turns this warning into an error, even.

What would be the best way to handle this?

Thanks,

Might this repository works for nim v1.6.0 ?

I have not yet fixed the code for Nim 1.6.0 from the book, but if I achieve it, may I propose a Pull Request to make the code functional in v1.6.0 or is this repository discontinued ?
I do not expect to make the code from metaprogramming chapter work (and there are better tutorials for macro in the standard library now).
Chapter3 - ChatClient: In protocol.nim, exceptions directly inherits from Exception but should inherit from a more precise Exception like IOError or ValueError. Apart from this, the client-server works.
Chapter6 - Wikipedia Stats : I believe Wikipedia has changed its API and it does not support pagecount anymore. (I have read the chapter a long time ago so I am not sure).
When I compile, I get that readChars is deprecated.
I had to change .. < into ..< into multiple files but apart from this, it compiles without trouble.
I will test other projects when I will have more time.

Returned values in Listing 7.30 should be reversed?

I think returned values in Listing 7.30 should be reversed.

proc userLogin(db: Database, request: Request, user: var User): bool =
  if request.cookies.hasKey("username"):
    if not db.findUser(request.cookies["username"], user):
      user = User(username: request.cookies["username"], following: @[])
      db.create(user)
      return false
    else:
      return true

Sequence code on Page 42 unable to compile

The below sequence code on Page 42 is not able to compile in nim 2.0:

let list = @[4, 8, 15, 16, 23, 42]
for i in 0 .. <list.len:
stdout.write($list[i] & " ")


Encountered the following error:
D:\nimTest\seqTest.nim(2, 15) Error: type mismatch
Expression: <=len(list)
[1] len(list): int

Expected one of (first mismatch at [position]):
[1] proc <=(x, y: bool): bool
[1] proc <=(x, y: char): bool
[1] proc <=(x, y: float): bool
[1] proc <=(x, y: float32): bool
[1] proc <=(x, y: int16): bool
[1] proc <=(x, y: int32): bool
[1] proc <=(x, y: int8): bool
[1] proc <=(x, y: pointer): bool
[1] proc <=(x, y: string): bool
[1] proc <=(x, y: uint): bool
[1] proc <=(x, y: uint16): bool
[1] proc <=(x, y: uint32): bool
[1] proc <=(x, y: uint64): bool
[1] proc <=(x, y: uint8): bool
[1] proc <=[Enum: enum](x, y: Enum): bool
[1] proc <=[T: tuple](x, y: T): bool
[1] proc <=[T](x, y: ref T): bool
[1] proc <=[T](x, y: set[T]): bool
[2] proc <=(x, y: int): bool
[2] proc <=(x, y: int64): bool

========================

However, removing the space after the '..' fix the issue.

let list = @[4, 8, 15, 16, 23, 42]
for i in 0 ..< list.len:
stdout.write($list[i] & " ")

Listing 7.14 Does Not Compile in Linux

Lines 82 and 84 in database.nim result in compilation errors under Linux!

Line 82 i.e. for i in 0 .. <usernames.len: is a common issue throughout the book and are remedied by removing the white spaces between the '0', '..' and '<' as follows:-
for i in 0..<usernames.len:

Whereas line 84 is simply non-sensical i.e. "if i != <usernames.len:"
I've tried altering to "if i != usernames.len:" and "if i < usernames.len:", etc. all to no avail as the following runtime error is encountered:-

../Tweeter/tests/database_test.nim(24) database_test
../Tweeter/src/database.nim(84) findMessages
~/.choosenim/toolchains/nim-1.2.6/lib/impure/db_sqlite.nim(257) getAllRows
~/.choosenim/toolchains/nim-1.2.6/lib/impure/db_sqlite.nim(217) setupQuery
~/.choosenim/toolchains/nim-1.2.6/lib/impure/db_sqlite.nim(142) dbError
Error: unhandled exception: near "ORDER": syntax error [DbError]

(program exited with code: 1)
Press return to continue

Please provide a fix as I actually went to the expense of paying for your book which is a highly unusual requirement to say the least as most programming languages are free to learn these days.

Aside from that, nice book btw albeit somewhat expensive especially considering the erroneous content in a number of places throughout.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.