mes_keyword.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. * Copyright © 2019 Jeremiah Orians
  5. *
  6. * This file is part of GNU Mes.
  7. *
  8. * GNU Mes is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * GNU Mes is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include "mes.h"
  22. /* Imported functions */
  23. struct cell* make_keyword(char* name);
  24. struct cell* make_sym(char* name);
  25. struct cell* builtin_keywordp(struct cell* args)
  26. {
  27. require(nil != args, "keyword? requires arguments\n");
  28. require(nil == args->cdr, "keyword? recieved too many arguments\n");
  29. if(KEYWORD == args->car->type) return cell_t;
  30. return cell_f;
  31. }
  32. struct cell* builtin_keyword_to_symbol(struct cell* args)
  33. {
  34. require(nil != args, "keyword->symbol requires arguments\n");
  35. require(nil == args->cdr, "keyword->symbol recieved too many arguments\n");
  36. require(KEYWORD == args->car->type, "keyword->symbol did not recieve a keyword\n");
  37. return make_sym(args->car->string + 2);
  38. }
  39. struct cell* builtin_string_to_keyword(struct cell* args)
  40. {
  41. require(nil != args, "string->keyword requires arguments\n");
  42. require(nil == args->cdr, "string->keyword recieved too many arguments\n");
  43. require(STRING == args->car->type, "string->keyword did not recieve a string\n");
  44. return make_keyword(args->car->string);
  45. }