Commits

Jürgen Bömmels  committed 9ff8fb6

Implement make-string

  • Participants
  • Parent commits d333d80

Comments (0)

Files changed (2)

File scheme/procedure.py

         # simply relay to map and ignore output
         (res, ctx) = Map().procedure_tr(ctx, lst)
         return (w_undefined, ctx)
-    
+
+class MakeString(W_Procedure):
+    _symbol_name = "make-string"
+
+    def procedure(self, ctx, lst):
+        if len(lst) < 1 or len(lst) > 2:
+            raise WrongArgsNumber
+
+        w_number = lst[0]
+        if not isinstance(w_number, W_Integer):
+            raise WrongArgType(w_number, "Integer")
+        
+        if len(lst) == 2:
+            w_char = lst[1]
+        else:
+            w_char = W_Character(' ')
+        if not isinstance(w_char, W_Character):
+            raise WrongArgType(w_char, "Character")
+
+        return W_String(w_char.to_string() * w_number.to_fixnum())
+
 ##
 # Equivalnece Predicates
 ##

File scheme/test/test_scheme_level.py

     (#f #f #f #f #f      #f       #f  #f     #f  #t    #f   #f) ; procedure?
     (#f #f #f #f #f      #f       #f  #f     #f  #f    #t   #t)); vector?
 ))
-""")
+""")
+
+def test_string():
+    run_with_assert(r"""
+(define new-str (make-string 7 #\*))
+(assert (string? new-str))
+(assert (equal? new-str "*******"))
+""")