Login
7 branches 0 tags
Ben (X13/Arch) Initial structs for Nujel images bd88c68 2 years ago 1086 Commits
nujel / stdlib / core / conversion.nuj
;;; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
;;; This project uses the MIT license, a copy should be included under /LICENSE
;;;
;;; Functions converting from one type to another

(defn keyword->string (kw)
      "Convert a keyword into a string

      kw: The input keyword

      Returns the string for kw"
      :cat :type-conversion
      :related string->keyword
      (deftest "asd" (keyword->string :asd))

      (when-not (keyword? kw) (exception :type-error "(keyword->string) can only be called on keywords" kw))
      (string (keyword->symbol kw)))

(defn string->keyword (kw)
      "Convert a string into a keyword

      kw: The input string

      Returns the keyword for kw"
      :cat :type-conversion
      :related keyword->string
      (deftest :asd (string->keyword "asd"))

      (when-not (string? kw) (exception :type-error "(string->keyword) can only be called on strings" kw))
      (symbol->keyword (string->symbol kw)))