From 06d19b28679c0feb46b8b6ff917bf7aec6d27004 Mon Sep 17 00:00:00 2001 From: Peter McGoron Date: Sun, 22 Sep 2024 12:09:09 -0400 Subject: [PATCH] miniscm: string->symbol and symbol->string --- miniscm/miniscm.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/miniscm/miniscm.c b/miniscm/miniscm.c index d2ec49f..315ed8e 100644 --- a/miniscm/miniscm.c +++ b/miniscm/miniscm.c @@ -1218,6 +1218,8 @@ register pointer a, b; #define OP_STRINGREF 112 #define OP_STRINGLEN 113 #define OP_LIST2STRING 114 +#define OP_STRING2SYMBOL 115 +#define OP_SYMBOL2STRING 116 static FILE *tmpfp; static int tok; @@ -1783,6 +1785,16 @@ register short op; } else { Error_0("char->integer: argument must be char"); } + case OP_STRING2SYMBOL: /* string->symbol */ + if (!isstring(car(args))) { + Error_0("string->symbol: argument must be string"); + } + s_return(mk_symbol(strvalue(car(args)))); + case OP_SYMBOL2STRING: /* symbol->string */ + if (!issymbol(car(args))) { + Error_0("symbol->string: argument must by symbol"); + } + s_return(mk_string(symname(car(args)))); default: sprintf(strbuff, "%d is illegal operator", operator); @@ -2529,7 +2541,9 @@ pointer (*dispatch_table[])() = { opexe_2, /* OP_CHAR2INT */ opexe_4, /* OP_STRINGREF */ opexe_4, /* OP_STRINGLEN */ - opexe_list2string /* OP_LIST2STRING */ + opexe_list2string, /* OP_LIST2STRING */ + opexe_2, /* OP_STRING2SYMBOL */ + opexe_2 /* OP_SYMBOL2STRING */ }; @@ -2692,6 +2706,8 @@ init_procs() mk_proc(OP_STRINGREF, "string-ref"); mk_proc(OP_STRINGLEN, "string-length"); mk_proc(OP_LIST2STRING, "list->string"); + mk_proc(OP_STRING2SYMBOL, "string->symbol"); + mk_proc(OP_SYMBOL2STRING, "symbol->string"); }