mirror of
https://github.com/samsonjs/lake.git
synced 2026-03-28 09:25:49 +00:00
- add booleans, dotted lists, functions - proper lexical scope - special forms: define, set!, and, or, quote, lambda - added some basic list manipulations - print functions and dotted lists - removed nil - more robust in general
50 lines
1 KiB
C
50 lines
1 KiB
C
/**
|
|
* dlist.c
|
|
* Lake Scheme
|
|
*
|
|
* Copyright 2011 Sami Samhuri
|
|
* MIT License
|
|
*
|
|
*/
|
|
|
|
#include "dlist.h"
|
|
#include "lake.h"
|
|
|
|
static LakeDottedList *dlist_alloc(void)
|
|
{
|
|
LakeDottedList *dlist = g_malloc(sizeof(LakeDottedList));
|
|
VAL(dlist)->type = TYPE_DLIST;
|
|
VAL(dlist)->size = sizeof(LakeDottedList);
|
|
return dlist;
|
|
}
|
|
|
|
LakeDottedList *dlist_make(LakeList *head, LakeVal *tail)
|
|
{
|
|
LakeDottedList *dlist = dlist_alloc();
|
|
dlist->head = head;
|
|
dlist->tail = tail;
|
|
return dlist;
|
|
}
|
|
|
|
char *dlist_repr(LakeDottedList *dlist)
|
|
{
|
|
GString *s = g_string_new("(");
|
|
int i;
|
|
char *s2;
|
|
if (dlist->head) {
|
|
for (i = 0; i < LIST_N(dlist->head); ++i) {
|
|
s2 = repr(LIST_VAL(dlist->head, i));
|
|
g_string_append(s, s2);
|
|
g_free(s2);
|
|
if (i != LIST_N(dlist->head) - 1) g_string_append(s, " ");
|
|
}
|
|
}
|
|
g_string_append(s, " . ");
|
|
s2 = repr(dlist->tail);
|
|
g_string_append(s, s2);
|
|
g_free(s2);
|
|
g_string_append(s, ")");
|
|
gchar *repr = s->str;
|
|
g_string_free(s, FALSE); /* don't free char data */
|
|
return repr;
|
|
}
|