summary refs log tree commit diff stats
path: root/lib/prelude.nim
blob: 940864207224061e5d8b920b162a6fdd45bfaedb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#
#            Nim's Runtime Library
#        (c) Copyright 2012 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## This is an include file that simply imports common modules for your
## convenience:
##
## .. code-block:: nim
##   include prelude
##
## Same as:
##
## .. code-block:: nim
##   import os, strutils, times, parseutils, parseopt, hashes, tables, sets

import os, strutils, times, parseutils, parseopt, hashes, tables, sets
>:address:shared:array:character ] memory-should-contain [ 2 <- 3 # array length 3 <- 0 4 <- 1 5 <- 2 ] ] # create an array out of a list of scalar args def new-array -> result:address:shared:array:character [ local-scope capacity:number <- copy 0 { # while read curr-value curr-value:character, exists?:boolean <- next-ingredient break-unless exists? capacity <- add capacity, 1 loop } result <- new character:type, capacity rewind-ingredients i:number <- copy 0 { # while read curr-value done?:boolean <- greater-or-equal i, capacity break-if done? curr-value:character, exists?:boolean <- next-ingredient assert exists?, [error in rewinding ingredients to new-array] tmp:address:character <- index-address *result, i *tmp <- copy curr-value i <- add i, 1 loop } return result ]