]> git.donarmstrong.com Git - lilypond.git/commitdiff
ly:truncate-list! ; robust version of srfi-1 (list-head)
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 5 Jan 2007 02:21:00 +0000 (03:21 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 5 Jan 2007 02:21:00 +0000 (03:21 +0100)
input/regression/general-scheme-bindings.ly
input/regression/profile-property-access.ly
lily/general-scheme.cc
lily/lily-guile.cc

index 6d93db7f2e558819edecfd0b87880c021432cd82..ad625ff25a7953f81024debc4d09be882ac71646 100644 (file)
@@ -8,10 +8,11 @@
 \version "2.11.8"
 
 %% todo : use macro, to show the statement tested. 
-#(ly:progress "~a" (ly:expand-environment "${HOME} $HOME $$ "))
+#(ly:progress "~a\n" (ly:expand-environment "${HOME} $HOME $$ "))
 #(ly:font-config-display-fonts)
-#(ly:progress "~A" (ly:duration->string (ly:make-duration 2 2 3 7)))
-
 
+#(ly:progress "~A\n" (ly:duration->string (ly:make-duration 2 2 3 7)))
 #(ly:parser-parse-string (ly:parser-clone parser) "foo  = #1 #(ly:progress \"hello there\n\")")
 
+#(ly:progress "~a\n" (ly:truncate-list! (iota 5) 10))
+#(ly:progress "~a\n" (ly:truncate-list! (iota 10) 5))
index 641c24fe70c092138b4bc1f9749819ef972684cc..21e5476b552c534a01576a361e65c6f4e43342a1 100644 (file)
@@ -26,7 +26,7 @@
    what count rnd
    (string-join
     (map (lambda (x) (format "~30a: ~6@a" (car x) (* rnd (inexact->exact (round (/ (cdr x) rnd))))))
-     (take 
+     (ly:truncate-list! 
     (sort alist prop-stats>?) count))
     "\n"))))
    
index a75ff511810131f31548e3cbf6c046768a37541a..dc236aa34ff60c001b860b383757a3e61cd958d8 100644 (file)
@@ -352,3 +352,27 @@ LY_DEFINE (ly_expand_environment, "ly:expand-environment",
   return ly_string2scm (expand_environment_variables (ly_scm2string (str)));
 }
                 
+
+LY_DEFINE (ly_truncate_list_x, "ly:truncate-list!",
+          2, 0, 0, (SCM lst, SCM i),
+          "Take at most the first @var{i} of list @var{lst}")
+{
+  SCM_ASSERT_TYPE(scm_is_integer (i), i,
+                 SCM_ARG1, __FUNCTION__, "integer");
+
+  int k = scm_to_int (i);
+  if (k == 0)
+    lst = SCM_EOL;
+  else
+    {
+      SCM s = lst;
+      k--;
+      for (; scm_is_pair (s) && k--; s = scm_cdr (s))
+       ;
+
+      if (scm_is_pair (s))
+       scm_set_cdr_x (s, SCM_EOL);
+    }
+  return lst;
+}
+
index 970a11bf62cfec32fbe1879b88b6d52ff5fac4e8..85628e64f8d69572d36660f4ddad700f2d99afc8 100644 (file)
@@ -406,25 +406,6 @@ ly_deep_copy (SCM src)
 }
 
 
-SCM
-ly_truncate_list (int k, SCM lst)
-{
-  if (k == 0)
-    lst = SCM_EOL;
-  else
-    {
-      SCM s = lst;
-      k--;
-      for (; scm_is_pair (s) && k--; s = scm_cdr (s))
-       ;
-
-      if (scm_is_pair (s))
-       scm_set_cdr_x (s, SCM_EOL);
-    }
-  return lst;
-}
-
-