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

What's the meaning of “magic” pragma in nim?
Unpack multiple variables from sequence
Nim: How to prove not nil?
Error: expression has no address
MD5 on an array, array[0..63, uint8] to cstring conversion
Converting a seq[char] to string
Nim: On mac, cannot open standard import
How to compare two typedesc in a template for equality
Is there a “default” file name that can be used for importing modules?
Unable to get StringStream created from marshal to output the data
Initialize a seq of seqs
How to change Nim compiler output file location and name
Compile-time Call Count in Nim
How To Convert Slice To Sequence?
Cannonical way to do circular dependency in Nim
toSeq(some_string) Type Mismatch

Categories

HOME
codenvy
pagination
ns-3
jelastic
graphics
entity-framework-core
hugo
regular-language
webix
boto3
mautic
emoji
line
spring-social
nancy
feathersjs
apache2.4
selinux
poedit
kendo-mobile
href
dataflow-diagram
joptionpane
dynamically-generated
strongname
interbase
nstimer
rpgle
winexe
twiml
turfjs
angularjs-material
fstream
memory-address
catch-unit-test
clickjacking
sammy.js
modalviewcontroller
latitude-longitude
salesforce-communities
git-rewrite-history
urlsession
branching-and-merging
postgresql-8.4
preloader
movilizer
sharp-snmp
apache-spark-dataset
servermanager
opennms
clarifai
spring-integration-sftp
facebook-pixel
google-cse
azure-cli
cup
trigger.io
polyline
smartfoxserver
adafruit
mapinfo
hclust
turbo-prolog
yajsw
nio2
dynatree
phonertc
canalyzer
iced-coffeescript
atoi
jdk1.7
uncompress
airbrake
nutiteq
qtwebengine
android-vibration
deform
visual-studio-express
gtm-oauth2
solace-mq
kendo-dataviz
ie8-compatibility-mode
ebay-lms
inappsettingskit
time.h
stacky
tree-balancing
zope.interface
adobe-media-server
httponly
isa-swizzling
google-ajax-api
massive
office-2007
ajax-polling
sifr
murmurhash
wcf-instancing
int64
pnrp

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