summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--doc/manual.txt6
-rw-r--r--lib/posix/posix.nim12
-rw-r--r--lib/pure/collections/sequtils.nim39
3 files changed, 54 insertions, 3 deletions
diff --git a/doc/manual.txt b/doc/manual.txt
index 2ccd4c1e9..b85c49e03 100644
--- a/doc/manual.txt
+++ b/doc/manual.txt
@@ -5172,9 +5172,9 @@ the same feature under the same name.
 Exportc pragma
 --------------
 The `exportc`:idx: pragma provides a means to export a type, a variable, or a
-procedure to C. The optional argument is a string containing the C identifier.
-If the argument is missing, the C name is the Nimrod
-identifier *exactly as spelled*:
+procedure to C. Enums and constants can't be exported. The optional argument
+is a string containing the C identifier.  If the argument is missing, the C
+name is the Nimrod identifier *exactly as spelled*:
 
 .. code-block:: Nimrod
   proc callme(formatstr: cstring) {.exportc: "callMe", varargs.}
diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim
index c3d5b5939..41260b36f 100644
--- a/lib/posix/posix.nim
+++ b/lib/posix/posix.nim
@@ -2566,3 +2566,15 @@ proc poll*(a1: ptr TPollfd, a2: Tnfds, a3: int): cint {.
 
 proc realpath*(name, resolved: cstring): cstring {.
   importc: "realpath", header: "<stdlib.h>".}
+
+proc utimes*(path: cstring, times: ptr array [2, Ttimeval]): int {.
+  importc: "utimes", header: "<sys/time.h>".}
+  ## Sets file access and modification times.
+  ##
+  ## Pass the filename and an array of times to set the access and modification
+  ## times respectively. If you pass nil as the array both attributes will be
+  ## set to the current time.
+  ##
+  ## Returns zero on success.
+  ##
+  ## For more information read http://www.unix.com/man-page/posix/3/utimes/.
diff --git a/lib/pure/collections/sequtils.nim b/lib/pure/collections/sequtils.nim
index 3993f1ccc..b2f72ee14 100644
--- a/lib/pure/collections/sequtils.nim
+++ b/lib/pure/collections/sequtils.nim
@@ -276,6 +276,38 @@ template foldr*(sequence, operation: expr): expr =
     result = operation
   result
 
+template mapIt*(seq1, typ, pred: expr): expr =
+  ## Convenience template around the ``map`` proc to reduce typing.
+  ##
+  ## The template injects the ``it`` variable which you can use directly in an
+  ## expression. You also need to pass as `typ` the type of the expression,
+  ## since the new returned sequence can have a different type than the
+  ## original.  Example:
+  ##
+  ## .. code-block:: nimrod
+  ##   let
+  ##     nums = @[1, 2, 3, 4]
+  ##     strings = nums.mapIt(string, $(4 * it))
+  var result {.gensym.}: seq[typ] = @[]
+  for it {.inject.} in items(seq1):
+    result.add(pred)
+  result
+
+template mapIt*(varSeq, pred: expr) =
+  ## Convenience template around the mutable ``map`` proc to reduce typing.
+  ##
+  ## The template injects the ``it`` variable which you can use directly in an
+  ## expression. The expression has to return the same type as the sequence you
+  ## are mutating. Example:
+  ##
+  ## .. code-block:: nimrod
+  ##   var nums = @[1, 2, 3, 4]
+  ##   nums.mapIt(it * 3)
+  ##   assert nums[0] + nums[3] == 15
+  for i in 0 .. <len(varSeq):
+    let it {.inject.} = varSeq[i]
+    varSeq[i] = pred
+
 when isMainModule:
   import strutils
   block: # concat test
@@ -381,4 +413,11 @@ when isMainModule:
     Inserting [2,2,2,2,2,2] into [1,1,1,1,1,1,1,1]
     at 3 is [1,1,1,2,2,2,2,2,2,1,1,1,1,1]"""
 
+  block: # mapIt tests
+    var
+      nums = @[1, 2, 3, 4]
+      strings = nums.mapIt(string, $(4 * it))
+    nums.mapIt(it * 3)
+    assert nums[0] + nums[3] == 15
+
   echo "Finished doc tests"