Nim version of Flask Web Framework

2020-04-16 Thread drifter
Hello,

Flask seems to be a popular python web framework. I was wondering if there was 
something similar for nim. I know of jester and rosenkrantz, but I am looking 
for something a bit more "batteries included".

Anyone working on anything like this?


Re: I have a super doubt

2020-02-20 Thread drifter
There is the book "Nim in Action". If you go to the nim home page and scroll 
down you will see.


Re: How to determine the type of an object

2019-03-23 Thread drifter
I feel honored receiving a reply from the maestro himself! 


Re: How to determine the type of an object

2019-03-23 Thread drifter
Stefan,

"is" is what I was looking for!. My use case is not very complicated as I'm 
just trying trying to learn by experimenting. The code was just an example.

I have some ideas on a project I want to make using nim, for example a 
translator that converts a markup to groff code.

The idea being to read the input and convert it to an AST, then traverse the 
AST, generating groff code based on the node type.

However after experimenting a bit more, I think what I have in mind is best 
achieved by writing a variety of "generate" methods each accepting a different 
parameter type, and leveraging dynamic dispatch to let the compiler decide 
which "generate" proc to use, depending on which node type is passed to it.

This way I could traverse the AST recursively, simply calling the same proc 
over and over.

for example:

method generate(element: H1) : string method generate(element: H2) : string 
method generate(element: UL) : string method generate(element: LI) : string 
method generate(element: P) : string

All this to say, although "is" is what I had in mind when posting the question, 
I'm realizing I may not need it after all if I leverage methods :)

yc


How to determine the type of an object

2019-03-22 Thread drifter
Hello,

I'm sure this functionality exists, however having a real hard time finding the 
answer.

How to you query the type of an object?

>From what I've been trying, type() only seems to work for primitive types.

I've also tried to find the answer in "Nim in Action".

In my search I also found the module typetraits, however name() doesn't seem to 
work either.

For example:

import strutils, typetraits, unicode 


type
  Token = object of RootObj
  Integer = ref object of Token
  String = ref object of Token

let d = Integer()
let c = String()

echo name(d)


Run

Gives: 


main.nim(17, 10) Error: type mismatch: got (Integer)
but expected one of:
proc name(t: typedesc): string
exit status 1


Run


Re: Documentation in PDF (for no programmer)

2019-03-11 Thread drifter
Wow, great-write up!


Re: Screencast Series Ideas

2019-02-16 Thread drifter
How about some screencasts about how to work with objects. Nim's class-less way 
of "OOP" is quite different than most languages people may be familiar with. 
Even though Nim's syntax is "pythonesque", its model is quite different.

For example I tried to follow 
[https://www.destroyallsoftware.com/screencasts/catalog/a-compiler-from-scratch](https://www.destroyallsoftware.com/screencasts/catalog/a-compiler-from-scratch)
 which is in Ruby. I've tried to follow something similar written in Go, and I 
always get tripped up on "damn, this is all classes and objects, how to I do 
the same thing in Nim?".


Suggestion - link the nimble package directory on the main page menu?

2018-08-20 Thread drifter
I never knew this package directory existed...

[https://nimble.directory](https://nimble.directory)/

Mostly I been looking on github for code.

Perhaps giving it a bit more exposure by linking it on the main landing page, 
alongside install, documentation, forum etc...?


Re: Lexers and parsers in nim

2018-08-19 Thread drifter
@cabhishek,

I'm wondering if you could explain a couple things in your lox interpreter code.

For example, sometimes you pass lexer as a var, sometimes not.


proc peek(lex: var Lexer): char
proc isAtEnd(lex: Lexer): bool


Run

Could you explain a little about this slight difference?

I've been doing something similar for the 


Run

lang, following:


://interpreterbook.com/

Run

In the Lox resource, the author uses Java as the implementation lang. For 
Monkey the author uses Go - a classless lang like Nim.

But in Go the author passes a pointer to the Lexer in order manipulate/modify 
state in the lexer.

In your code I see Lexer is simply an object, not a ref object or a ptr.

Does defining the parameter as proc(lex: var Lexer) behave similar to a 
pointer? This has the result of mutating state in the Lexer object? In other 
words, it's like passing by reference rather than by value?

Another question, do you intend to experiment converting the Lox AST to Nim AST 
and as a result have it become a compiled language rather than an interpreted 
one? 


Undeclared identifier even when .nim file is properly imported

2018-08-12 Thread drifter
Hi there, I'm wondering if you had managed to resolve this issue, as I'm 
running into the same problem.


Re: Lessons learned/idioms

2018-08-12 Thread drifter
hi there, I found 
[https://scripter.co/notes/nim](https://scripter.co/notes/nim)/ to be very 
useful.


Re: Simple Web/DB CRUD Example

2018-07-28 Thread drifter
this is perfect, thank you!


Simple Web/DB CRUD Example

2018-07-28 Thread drifter
Hello,

I would like to know if there are any basic web server/DB CRUD examples that I 
could follow?


Re: Working with Objects

2018-01-09 Thread drifter
Thanks so much for this...pointer 

Works like a charm now.


Working with Objects

2018-01-09 Thread drifter
Hi there,

I'm working through the very excellent "Write an Interpreter in Go" 
([https://interpreterbook.com/](https://interpreterbook.com/))

I'm trying to follow the book but implementing in nim rather than Go, but 
running into a wall trying to translate Go into Nim.

For example passing pointers to objects or returning pointers to objects.

An example in Go


/* A lexer */
type Lexer struct {
   input string
   position int
   readPosition int
   ch byte
}

/* Function to create a new lexer */
func New(input string) *Lexer {
  l := &Lexer{input: input}
}


Translating to nim I have:


type TLexer = object
  input : string
  position  : int
  readPosition : int
  ch: byte

proc new(input : string) : TLexer =
  let l = new TLexer(input, 0, 0, 0)
  return l


but I know I'm not doing this well. #1 Not sure how to create a Lexer object #2 
Not sure how to return a pointer from a proc.

Initially I tried defining the Lexer as


type Lexer = ref object
 ...


But that did not compile.

I also tried defining the proc as


proc New(input: string): ref Lexer =
 


But also didn't compile.

The nim way of working with objects is a bit new to me. I'm sure it's something 
very simple but not sure what is that little bit I'm nt getting. 


Re: Flow Based Programming in Nim

2016-10-06 Thread drifter
Runvnc,this was a quite a detailed answer :) Ihave to thank you for taking the 
time for chiming in and providing all of these links.

Seems I have quite a bit of reading to do.

Thank very much,


Flow Based Programming in Nim

2016-10-01 Thread drifter
Hi there, I've been reading up on a programming model referred to as Flow-Based 
Programming (FBP).

[http://www.jpaulmorrison.com/fbp](http://forum.nim-lang.org///www.jpaulmorrison.com/fbp)/
 
[https://en.wikipedia.org/wiki/Flow-based_programming](https://en.wikipedia.org/wiki/Flow-based_programming)

I'm wondering if any of you have implemented something like this in Nim?

Central to FBP is the concept that **data** is to be seen as the primary 
"thing" in an application, This "thing" moves from one process to another, 
undergoing a constant series of transformations.

Processes receive and send packets of information between each other.

The sole purpose of a process is to transform the data it receives into another 
form, before sending it off to another process.

A few other highlights:

  1. A process has IN and OUT channels (kind of like a socket's receive and 
send)
  2. Processes are connected together (ex: connect("ProcessA.OUT", 
"ProcessB.IN") to create a network of interconnected processes
  3. Data (Information Packets) is received by the receiving process(es) in the 
order in which they were sent by the sending process
  4. Once they have finished transforming the data they have received, a 
receiving process sits iddle until new data is sent to it.



I could see model working well for making the jump from process diagrams into 
code implementation, almost having a 1:1 relationship. Well, especially in my 
line of work as a IT Biz Analyst where we do a lot of process diagrams. Mapping 
a process diagram to a process using this approach would seem trivial.

The only thing is I'm not quite sure how to implement this in Nim (well, in any 
langauge in general).

The author of "Flow Based Programming", Paul Morrison, pointed me to a couple 
of implementations of this approach:

[http://www.jpaulmorrison.com/fbp/jsyntax.htm](http://forum.nim-lang.org///www.jpaulmorrison.com/fbp/jsyntax.htm)

This approach has been implemented in Java, in C++, Javascript. He tells me 
implementation of this approach depends on the language being used supporting 
threads (which I know Nim does). But I have to admit I'm not strong enough a 
programmer to figure it out on my own.

So if anyone is interested, and have a few ideas or pointers, I hope you don't 
mind chiming in!

Regards,