summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@xs4all.nl>2007-01-05 03:21:00 +0100
committerHan-Wen Nienhuys <hanwen@xs4all.nl>2007-01-05 03:21:00 +0100
commitf63b7e7f12fa7757efbf89925afa39b1a2738f68 (patch)
treefa7bd6133687ab96cc6a32cdb6b27fa57810db84
parent433b97931cbe1b8a695d6a7f33e58f44749a7a7a (diff)
ly:truncate-list! ; robust version of srfi-1 (list-head)
-rw-r--r--input/regression/general-scheme-bindings.ly7
-rw-r--r--input/regression/profile-property-access.ly2
-rw-r--r--lily/general-scheme.cc24
-rw-r--r--lily/lily-guile.cc19
4 files changed, 29 insertions, 23 deletions
diff --git a/input/regression/general-scheme-bindings.ly b/input/regression/general-scheme-bindings.ly
index 6d93db7f2e..ad625ff25a 100644
--- a/input/regression/general-scheme-bindings.ly
+++ b/input/regression/general-scheme-bindings.ly
@@ -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))
diff --git a/input/regression/profile-property-access.ly b/input/regression/profile-property-access.ly
index 641c24fe70..21e5476b55 100644
--- a/input/regression/profile-property-access.ly
+++ b/input/regression/profile-property-access.ly
@@ -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"))))
diff --git a/lily/general-scheme.cc b/lily/general-scheme.cc
index a75ff51181..dc236aa34f 100644
--- a/lily/general-scheme.cc
+++ b/lily/general-scheme.cc
@@ -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;
+}
+
diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc
index 970a11bf62..85628e64f8 100644
--- a/lily/lily-guile.cc
+++ b/lily/lily-guile.cc
@@ -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;
-}
-
-