Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Reverse-a-string/Fe/reverse-a-string-1.fe
Normal file
25
Task/Reverse-a-string/Fe/reverse-a-string-1.fe
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#define MAXSTRINGLEN ( 1024 )
|
||||
|
||||
/* chop string to list of single character strings */
|
||||
static fe_Object* chop(fe_Context *ctx, fe_Object *args) {
|
||||
char buf[MAXSTRINGLEN];
|
||||
int len = fe_tostring(ctx, fe_nextarg(ctx, &args), buf, sizeof(buf));
|
||||
int gc = fe_savegc(ctx);
|
||||
args = fe_bool(ctx, 0);
|
||||
while (len > 0) {
|
||||
buf[len--] = '\0';
|
||||
args = fe_cons(ctx, fe_string(ctx, buf + len), args);
|
||||
fe_restoregc(ctx, gc);
|
||||
fe_pushgc(ctx, args);
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
/* pack list of strings to single string */
|
||||
static fe_Object* pack(fe_Context *ctx, fe_Object *args) {
|
||||
char buf[MAXSTRINGLEN], *ptr = buf;
|
||||
for (args = fe_nextarg(ctx, &args); !fe_isnil(ctx, args);) {
|
||||
ptr += fe_tostring(ctx, fe_nextarg(ctx, &args), ptr, buf + sizeof(buf) - ptr);
|
||||
}
|
||||
return fe_string(ctx, buf);
|
||||
}
|
||||
10
Task/Reverse-a-string/Fe/reverse-a-string-2.fe
Normal file
10
Task/Reverse-a-string/Fe/reverse-a-string-2.fe
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
; reverse list
|
||||
(= reverse (fn (lst)
|
||||
(let res nil)
|
||||
(while lst
|
||||
(= res (cons (car lst) res))
|
||||
(= lst (cdr lst)))
|
||||
res))
|
||||
|
||||
; chop string to list, reverse list and pack it back to string
|
||||
(print (pack (reverse (chop "Hello world!"))))
|
||||
1
Task/Reverse-a-string/Fe/reverse-a-string-3.fe
Normal file
1
Task/Reverse-a-string/Fe/reverse-a-string-3.fe
Normal file
|
|
@ -0,0 +1 @@
|
|||
!dlrow olleH
|
||||
Loading…
Add table
Add a link
Reference in a new issue