]> git.donarmstrong.com Git - lilypond.git/blob - lily/lily-guile.cc
patch::: 1.1.2.hwn1
[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   Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 */
10
11 #include <stdio.h>
12 #include "libc-extension.hh"
13 #include "lily-guile.hh"
14 #include "main.hh"
15
16 SCM
17 ly_append (SCM a, SCM b)
18 {
19   return gh_call2 (gh_eval_str ("append"), a, b);
20 }
21
22 SCM
23 ly_list1 (SCM a)
24 {
25   return gh_call1 (gh_eval_str ("list"), a);
26 }
27
28 SCM
29 ly_quote ()
30 {
31   return gh_eval_str ("'quote");
32 }
33
34 SCM
35 ly_quote_scm (SCM s)
36 {
37   return gh_list (ly_quote (), s, SCM_UNDEFINED);
38 }
39
40 SCM
41 ly_eval (SCM a)
42 {
43   return gh_call1 (gh_eval_str ("eval"), a);
44 }
45
46 SCM
47 ly_lambda_o ()
48 {
49   return gh_eval_str ("'(lambda (o))");
50 }
51
52 SCM
53 ly_func_o (char const* name)
54 {
55   char buf[200];                // ugh.
56   snprintf (buf, 200, "'(%s o)", name);
57   return gh_eval_str (buf);
58 }
59
60
61 SCM
62 lambda_scm (String str, Array<int> args_arr)
63 {
64   if (str.empty_b ())
65     {
66       str = "empty";
67       args_arr.clear ();
68     }
69   SCM args_scm = SCM_EOL;
70   for (int i = args_arr.size () - 1; i >= 0; i--)
71     args_scm = gh_cons (gh_int2scm (args_arr[i]), args_scm);
72   SCM scm =
73     ly_append (ly_lambda_o (), 
74     ly_list1 (ly_append (ly_func_o (str.ch_l ()), args_scm)));
75   return scm;
76 }
77
78 SCM
79 lambda_scm (String str, Array<Scalar> args_arr)
80 {
81   if (str.empty_b ())
82     {
83       str = "empty";
84       args_arr.clear ();
85     }
86   SCM args_scm = SCM_EOL;
87   for (int i = args_arr.size () - 1; i >= 0; i--)
88     args_scm = gh_cons (gh_str02scm (args_arr[i].ch_l ()), args_scm);
89   SCM scm =
90     ly_append (ly_lambda_o (), 
91     ly_list1 (ly_append (ly_func_o (str.ch_l ()), args_scm)));
92   return scm;
93 }
94
95 SCM
96 lambda_scm (String str, Array<Real> args_arr)
97 {
98   if (str.empty_b ())
99     {
100       str = "empty";
101       args_arr.clear ();
102     }
103   SCM args_scm = SCM_EOL;
104   for (int i = args_arr.size () - 1; i >= 0; i--)
105     args_scm = gh_cons (gh_double2scm (args_arr[i]), args_scm);
106   SCM scm =
107     ly_append (ly_lambda_o (), 
108     ly_list1 (ly_append (ly_func_o (str.ch_l ()), args_scm)));
109   return scm;
110 }
111
112