Add CT331 Programming Paradigms

This commit is contained in:
2023-12-07 01:33:53 +00:00
parent 38a012c323
commit 262614ce83
207 changed files with 4516 additions and 0 deletions

View File

@ -0,0 +1,22 @@
#lang racket
;; a cons pair of two numbers
(cons 1 2)
;; a list of 3 numbers using only the cons function
;; this could be more easily done using the single quote `'` (i.e., `'(1 2 3)`) but i don't use it as it seemed against the spirit of the question
(cons 1 (cons 2 (cons 3 empty)))
;; a list containing a string, a number, and a nested list of three numbers using only the cons function
(cons "a string"
(cons 0
(cons (cons 1 (cons 2 (cons 3 empty))) empty)
)
)
;; a list containing a string, a number, and a nested list of three numbers, using only the list function
(list "a string" 0 (list 1 2 3))
;; a list containing a string, a number, and a nested list of three numbers, using only the append function
;; using `'` as the arguments of the `append` function must be themselves lists
(append '("a string") '(0) '((1 2 3)))