nim


Basic string formatting with NIM


I am trying to do some very basic string formatting and I got immediately stuck.
What is wrong with this code?
import strutils
import parseopt2
for kind, key, val in getopt():
echo "$1 $2 $3" % [kind, key, val]
I get Error: type mismatch: got (TaintedString) but expected 'CmdLineKind = enum' but I don't understand how shall I fix it.
The problem here is that Nim's formatting operator % expects an array of objects with the same type. Since the first element of the array here has the CmdLineKind enum type, the compiler expects the rest of the elements to have the same type. Obviously, what you really want is all of the elements to have the string type and you can enforce this by explicitly converting the first paramter to string (with the $ operator).
import strutils
import parseopt2
for kind, key, val in getopt():
echo "$1 $2 $3" % [$kind, key, val]
In case, you are also wondering what is this TaintedString type appearing in the error message, this is a special type indicating a non-validated external input to the program. Since non-validated input data poses a security risk, the language supports a special "taint mode", which helps you keep track of where the inputs may need validation. This mode is inspired by a similar set of features available in the Perl programming language:
http://docstore.mik.ua/orelly/linux/cgi/ch08_04.htm

Related Links

How to use Nim's `of` operator with generics?
Unable to build nimsuggest
Nim: How to check if a float is nan or inf?
How to help nim prove that indices from an iterator are disjoint (within parallel section)?
printing an array in Nim using echo
Nim stored procedure reference in tuple
Remove constant after compilation in Nim
How do I use a `concept` in Nim?
how to create an IntSet on the heap in nim?
How to benchmark few lines of code in nim?
what is nim type definition for generic procedure?
Does a nim library contain an argsort implementation or wrapper?
nim jester how to change static route and directory
nim linker error while linking to libsodium
Can countup and countdown iterators in Nim language be used in variable declaration?
How do I write unit test for code that should fail to compile in Nim?

Categories

HOME
developer-tools
flex
jsf-2.2
socket.io
vxml
emscripten
maxscript
hpc
sendgrid-api-v3
augeas
32bit-64bit
java.util.logging
frequency-distribution
scrolltop
android-intent
null-pointer
smartclient
cfml
boost-icl
blade
inno-download-plugin
exit
easeljs
mongoid6
event-store
gmock
asymptotic-complexity
firebase-analytics
iis-express
gitlab-api
record
memory-address
catch-unit-test
github3.py
sendbird
dynamic-jasper
lubridate
xajax
engine.io
google-knowledge-graph
cd
projects-and-solutions
bc
health-monitoring
dcmtk
wmp
clang++
tinymce-3
reindex
custom-font
static-cast
django-1.10
testrail
choice
segment-io
macaulay2
hadoop-partitioning
boost-serialization
nio2
kendo-upload
jaunt-api
phpgrid
sapi
forwarding
binomial-theorem
toolkit
mod-proxy
haskell-warp
apache-commons-daemon
alloy-ui
teamcity-9.1
snackbar
cakephp-2.7
code-documentation
qtwebengine
apache-spark-1.3
cocos3d
mobility
radiant
ecslidingviewcontroller
ora-06550
artemis
gd-graph
sphinxql
jammer
hidapi
workitem
node-blade
windows-98
mkv
pstack
jquery-blockui
jdb
kqueue
google-maps-mobile
clrstoredprocedure
mtu
objective-j
undefined-index
silent
hbm2java
fdf
image-capture

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App