]> git.donarmstrong.com Git - lilypond.git/blob - lily/lily-guile.cc
daa7588554908930a8eb8376e471f8da18baa993
[lilypond.git] / lily / lily-guile.cc
1 /*
2   lily-guile.cc -- implement assorted guile functions
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <stdio.h>
10 #include "libc-extension.hh"
11 #include "lily-guile.hh"
12 #include "main.hh"
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 SCM
19 ly_append (SCM a, SCM b)
20 {
21   return gh_call2 (gh_eval_str ("append"), a, b);
22 }
23
24 SCM
25 ly_list1 (SCM a)
26 {
27   return gh_call1 (gh_eval_str ("list"), a);
28 }
29
30 SCM
31 ly_list2(SCM a, SCM b)
32 {
33   return gh_call2 (gh_eval_str ("list"), a, b);
34 }
35
36 SCM
37 ly_quote ()
38 {
39   return gh_eval_str ("'quote");
40 }
41
42 SCM
43 ly_eval (SCM a)
44 {
45   return gh_call1 (gh_eval_str ("eval"), a);
46 }
47
48 SCM
49 ly_lambda_o ()
50 {
51   return gh_eval_str ("'(lambda (o))");
52 }
53
54 SCM
55 ly_func_o (char const* name)
56 {
57   char buf[200];
58   snprintf (buf, 200, "'(%s o)", name);
59   return gh_eval_str (buf);
60 }
61
62 #ifdef __cplusplus
63 }
64 #endif
65
66 SCM
67 lambda_scm (String str, Array<Scalar> args_arr)
68 {
69   if (str.empty_b ())
70     {
71       str = "empty";
72       args_arr.clear ();
73     }
74   SCM args_scm = SCM_EOL;
75   for (int i = args_arr.size () - 1; i >= 0; i--)
76     args_scm = gh_cons (gh_str02scm (args_arr[i].ch_l ()), args_scm);
77   SCM scm =
78     ly_append (ly_lambda_o (), 
79     ly_list1 (ly_append (ly_func_o (str.ch_l ()), args_scm)));
80   return scm;
81 }
82
83 SCM
84 lambda_scm (String str, Array<Real> args_arr)
85 {
86   if (str.empty_b ())
87     {
88       str = "empty";
89       args_arr.clear ();
90     }
91   SCM args_scm = SCM_EOL;
92   for (int i = args_arr.size () - 1; i >= 0; i--)
93     args_scm = gh_cons (gh_double2scm (args_arr[i]), args_scm);
94   SCM scm =
95     ly_append (ly_lambda_o (), 
96     ly_list1 (ly_append (ly_func_o (str.ch_l ()), args_scm)));
97   return scm;
98 }
99