Hello Zedeus, thanks for the pointer! I appreciate it! I see that your changes
would be for a POST request. Would they also work for a PUT request? Many
thanks and hope your day goes well, adil
Since your `properQuote` doesn't quote at all, it is neither correct nor safe.
To prevent SQL injections, use the existing `db_*` modules from the stdlib.
> please write Nim code like this
Maybe I missed a lot, but I have no idea what that part of your answer may mean
and how it may help for the initial question.
I mean if you want to import module dynaically, yon can write it directly into
file or use when flag. for example,
import streams, strformat
let
module = readline(stdin)
tempFile = getTempDir() & "timeit_temp.nim"
var temp = newFileStream(tempFile, fmWrite)
Alright thanks anyway for the answer :) That atleast got me halfway...
How can I return the value that is returned in a proc inside the
timeit_temp.nim?
So here is my code:
proc runNimProcFromAnotherFile(filename: string) =
#[ I need to import the filename and use the proc defined inside it...]#
Run
How do I import the file and return the proc inside it?
Thanks.
I have no idea.
https://nim-lang.org/docs/tut1.html#modules
What I want is a TableRef which would available for every thread. Read-only
access is enough.
Here's another way of compiling on Android natively - works great when you have
an external monitor and keyboard connected to your phone (the wonders of usbc
and bluetooth):
[https://our.status.im/building-nimbus-on-android](https://our.status.im/building-nimbus-on-android)/
That isn't what I wanted @kidandcat. To better explain my question:
proc importNewModule(module: string) =
import module # this is just for illustration, it won't work I know. How
do I do that?
something()
Run
And the module is something like this...
Why do you want to import it at runtime?
Hello everyone!
I am developing some DSLs using nim's macro system, and I would like to
implement my own function syntax. My aim is to have the syntax to look quite
similarly to Python's `def`
([https://docs.python.org/3/library/typing.html)](https://docs.python.org/3/library/typing.html\)).
H
Just put all import at top of file and should work. Nim is Compiled, all import
are resolved at compile time.
const some_module {.strdefine.} = "some_module"
template makeAnImport(module: static[string]): untyped = import module
makeAnImport(some_module)
Run
:)
Thank you for the answer I understand, too bad it would have standardized
I think there's some misunderstanding here. The short answer to "is this
possible?" is no, this is not possible. Since nim is a compiled language, all
imported modules have to be compiled and embedded in the resulting binary. It
is possible in dynamic languages that offer eval of some sort, but
Hi @iwcoetzer,
Araq is correct, your properQuote doesn't do anything. To get a big portion of
SQL injection safety, always use parameterised queries. Never combine strings
with SQL. As soon as you start combining text for queries, you're in trouble.
For example, this is a bad idea:
Thanks that helped me understand it better :) What do you have to say about
@juancarlospaco 's answer?
That's just another method of doing it at compile time. Nim only supports
compile time importing. Because it has to compile modules. Compiling is done
once for the whole program.
juan's snippet still resolves import at compiletime. nim is not python.
If the lexer doesn't like it there's nothing you can do unless Nim can be
changed to allow it. There are other things the lexer doesn't like outside of
where they belong, such as open block statements that have commas, objects,
enums, concepts, object case field: Type syntax, postfix * for expor
@yglukhov, I am keen to understand the embedding of nim compiler. Could you
give a example for the same?
Alrightyy! Thanks all for the answer.
See
[https://github.com/nim-lang/Nim/blob/devel/tests/compilerapi/tcompilerapi.nim](https://github.com/nim-lang/Nim/blob/devel/tests/compilerapi/tcompilerapi.nim)
and
[https://github.com/nim-lang/Nim/tree/devel/tests/compilerapi](https://github.com/nim-lang/Nim/tree/devel/tests/compilerapi)
for
you can also consider creating shared object files and load them. Depending on
your use case this might be "dynamic" enough?
The idiomatic way is to use `proc foo(args: ...): ... {.customMacro.}`.
I see. Well, it's kind of weird though that that specific syntax works with
other symbols that are not `:`. I'm working towards an intermediate solution
that creates temporary .nim files that turn `a : T = x` constructs into `a T =
x` ones, and using these latter ones in the macro logic. It stil
What do you mean?
I wouldn't want the users of my DSL to interface with the `proc` construct
directly, but to deal with `my_func` (or `def`, or whatever name I come up
with), as many things are abstracted in the macro to make the DSL work.
By the way, the DSL is for DSP and audio synthesis, it'
Well Nim DSLs work better when they feel like Nim DSLs. In the macro you can
transform and reinterpret `proc` declarations all you want, there is no need
for `def`.
I see your point, but I find `proc foo(args: ...): ... {.customMacro.}` to be
not so user friendly compared to simply `def foo(args: ...):`.
Especially considering that I am building this DSL also for teaching/learning
purpose of DSP/audio algorithms, so I can expect people using it not to have
Ooh! That seems perfect...I'll test that out. Thanks.
> Finally - and most importantly as I've detailed above, db_odbc doesn't use
> parameterisation and instead just uses string concatination, so injections
> are still possible:
> [https://github.com/nim-lang/Nim/blob/b6924383df63c91f0ad6baf63d0b1aa84f9329b7/lib/impure/db_odbc.nim#L194](https://gi
How do I change an element valut at runtime? I know changeName.text = n.values
is incorrect but what should it be?
include karax / prelude
import karax / [vstyles]
proc onNameEnter(ev: Event; n: VNode) =
if n.value.strip() != "":
changeName.text
`include karax / prelude import karax / [vstyles] var myText = "Name will apear
here." proc onNameEnter(ev: Event; n: VNode) = if n.value.strip() != "": myText
= n.values proc createDom(): VNode = result = buildHtml(tdiv): h1(id =
"changeName"): text myText form: label(`for` = "fname"): text "En
Thank you kidandcat. But I still did not get it to work.
I changed
myText = "Name will appear here"
to
myText: kstring = "Name will appear here"
as it said that it was expecting a string but was getting a kstring.
Also found a typo I made
myText = n.values
to
myText = n.value
Th
Use AcVim can prompt nim libs function, template, macro name ... now
Easier to write nim code, Hope you like it :)
If you insist (and I agree with Araq you probably shouldn't ... ), you should
probably be aware of
[https://nim-lang.org/docs/filters.html](https://nim-lang.org/docs/filters.html)
which would allow you to do such a translation in a standard, compose-able
manner -- which may boil down to just re
You can't dynamically import a module in Nim because it is a statically
compiled language, (you end with your binary, you don't distribute the source
code)
If you want to do that, you can compile your library as a shared library, but
I'm 100% sure you don't need to do that to achieve what you w
I dont think onkeyupenter is a valid event
Following code runs into problems when using different types of Generators. A
Generator is just a proc with no parameters that returns some type of value.
[https://play.nim-lang.org/#ix=2cRz](https://play.nim-lang.org/#ix=2cRz)
import macros, sugar
type Generator[T] = () ->
Don't know if this is the proper way to do it, but you can get/set the
innerHTML.
let n = getVNodeById("changeName")
echo n.innerHTML
n.innerHTML = kstring("my new string")
Run
I don't understand what you actually want to accomplish, but I'm pretty sure
you don't actually want a generic macro.
But your "would love to do that" idea actually works, with a small
modification. Just don't use explicit types, but use varargs[typed]. Then you
can extract the type information
Cool. Didn't realize there is getTypeImpl and getImpl. I'll try it out. Thanks.
I just wanted to say this language is fantastic. I just finished a -- to me --
medium-sized project for work yesterday that took about a week (including
modifying & wrapping a C library to replace `httpclient` for static compiling
with SSL/TLS, but that's another story...) and I had decided to u
@herdingSheep
Based on @hiteshjasani's answer, this is a tested, working example:
include karax / prelude
import karax / [vstyles]
var name: kstring = "Name will appear here"
proc createDom(): VNode =
result = buildHtml(tdiv):
h1(id = "changeName")
Ubuntu's inbuilt text editor Gedit is quite good for quick coding.
I use the Python 3 highlighting for Nim but it would be good if we have one for
Nim too.
Or, is it already there?
@kidandcat, I discovered the nim compiler api which seems perfect for my use.
[https://forum.nim-lang.org/t/5994](https://forum.nim-lang.org/t/5994)
Also, the example you provided just calls out the nim compiler without
returning any exported proc inside it. (Because it's runtime)
Is there any
Here's a better example. It's modified from some code I'm working on but should
work. The H1 will update automatically as you type characters into the text
field. The text field itself actually won't update without us explicitly
changing its value using setInputText(). Not sure if that's intende
> Arrogance definitely leads to ignorance.
> \-- N/A
[How to Print Floating-Point Numbers
Accurately](http://kurtstephens.com/files/p372-steele.pdf) by Guy L. Steele Jr.
and Jon L White.
As a bonus, this paper also gives hints on how to read floating point numbers
accurately.
I have a union type ContentNode can be either a P, Br, or Text. The P can have
children of type ContentNode:
type
ContentNodeKind* = enum
P,
Br,
Text
ContentNode* = object
case kind*: ContentNodeKind
of P: pChildren*: seq[ContentNod
If you don't really care about speed - you could use the built in Nim
compiler+virtiual machine as a script interpreter, (though IIRC there are
limits by default that may surprise you and that can be removed, e.g. how many
iterations a single loop can have is limited to 1,000,000 as this is mean
Maybe also have a look at cligen (
[https://github.com/c-blake/cligen](https://github.com/c-blake/cligen) )
method getresultTwo(self: ResultEngine, connectionEngine:
ConnectionEngine): SQLResults {.base.} =
self.query = newQuery(connectionEngine.connection)
self.query.statement = ("SELECT * FROM dbo.Contract WHERE
EffectivePeriod >= ?value1", [("value1", 201906)])
self.quer
This also did not work ...
method getresultThree(self: ResultEngine, connectionEngine:
ConnectionEngine): SQLResults {.base.} =
let results = connectionEngine.connection.dbq("SELECT * FROM
dbo.DimContract WHERE EffectivePeriod >= ?value1", [("value1", 201906)])
retur
56 matches
Mail list logo