Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
kr committed Mar 17, 2009
1 parent 88f4f50 commit cec3bcb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
20 changes: 18 additions & 2 deletions bytes.na
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

inline C <<end

#include <string.h>
Expand Down Expand Up @@ -290,4 +289,21 @@ def (to-str x):
. x
to-str (x.str)

. '()
def maker: obj:
inline C run <<end
datum x;
uint n = 0;

for (x = args; pairp(x); x = cdr(x)) n++;

{
uint i = 0;
char buf[n];
for (x = args; pairp(x); x = cdr(x)) {
buf[i++] = datum2int(car(x));
}
return make_bytes_init_len(buf, n);
}
end

maker
7 changes: 6 additions & 1 deletion pair.na
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export list

inline C <<end

Expand Down Expand Up @@ -57,4 +58,8 @@ def pair: sobj:
(assq name):
? (is? (self.car.car) name) (self.car) (self.cdr.assq name)

. '()
def list: obj:
inline C run <<end
return args;
end

22 changes: 2 additions & 20 deletions prelude.na
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,9 @@ def (map f a):
def x (f a.car) # evaluate x before the rest
cons x (map f a.cdr)

def list: obj:
inline C run <<end
return args;
end
import pair list

def bytes: obj:
inline C run <<end
datum x;
uint n = 0;

for (x = args; pairp(x); x = cdr(x)) n++;

{
uint i = 0;
char buf[n];
for (x = args; pairp(x); x = cdr(x)) {
buf[i++] = datum2int(car(x));
}
return make_bytes_init_len(buf, n);
}
end
import bytes

def (assq x a):
if (is? a '()): return a
Expand Down

0 comments on commit cec3bcb

Please sign in to comment.