Questions tagged [special-form]

15 questions
15
votes
7 answers

can if be a proper function rather than a special form

I finally started learning functional languages (emacs lisp) and it makes explicit distinction between functions and special forms such as flow control , for example if. Is there a fundamental/theoretical reason why special forms are distinct from…
Anycorn
  • 50,217
  • 42
  • 167
  • 261
8
votes
1 answer

Is there a way to get a collection of clojure special forms programatically?

Does something similar to this exist?: (deftest fantasy (is (= ["let" "def" "ns" "etc."] clojure.core/special-chars)))
Nick Orton
  • 3,563
  • 2
  • 21
  • 28
6
votes
1 answer

Why is do a special form?

In Clojure, why is do a special form, instead of a function implemented like this? (defn do [& exprs] (last exprs))
Sam Estep
  • 12,974
  • 2
  • 37
  • 75
5
votes
2 answers

Scheme/Racket: Fold with booleans

(foldr + 0 '(1 2 3 4)) returns 10 which is what I expect, but (foldr and false '(true true false)) gives me the error and: expected an open parenthesis before and, but found none foldr takes a function (which takes two parameters, since I have…
newprogrammer
  • 2,514
  • 2
  • 28
  • 46
3
votes
5 answers

How is "+" Implemented in Common Lisp Using Special Operators/Forms

In On Lisp (page 9), one can find the following claim: Functions are the building-blocks of Lisp programs. They are also the building-blocks of Lisp. In most languages the + operator is something quite different from user-defined functions. But…
MadPhysicist
  • 5,401
  • 11
  • 42
  • 107
3
votes
2 answers

What does the 'do' special form do?

Documentation says: (do exprs*) Evaluates the expressions in order and returns the value of the last. If no expressions are supplied, returns nil. However, I just did this: (defn blah [] (print "how") (print "now") (print "brown") …
user1992634
  • 764
  • 7
  • 16
2
votes
3 answers

Clojure asterisks special forms (fn*, let*, etc...)

I discovered that a lot of "special forms" are just macros that use their asterisks version in the background (fn*, let* and all the others). In case of fn, for example, it adds the destructuring capability into the mix which fn* alone does not…
Lazarus535
  • 1,158
  • 1
  • 8
  • 23
2
votes
1 answer

Dynamic symbols in Clojure Macro/Special Form

I have a question regarding how to define functions/macros which call other macros or special forms but where one of the symbols passed in needs to be dynamic. The simplest version of this question is described below: We can define variables using…
WuHoUnited
  • 8,279
  • 3
  • 24
  • 27
1
vote
3 answers

Is the "else" keyword, used as final case in a cond-expression, a special form in Scheme?

The cond-expression in Scheme is a special form, but is the else keyword, used as final case in a cond-expression, a special form? Or is it just a reserved keyword that is essentially equivalent to the truth-value #t ? In the latter case, why cannot…
1
vote
1 answer

Elixir macros, quoting bitstring patternmatch types

I am working on a project in which I am likely to be writing a lot of code of the form: defmodule Kind defstruct [name1, name2, name3] @type t :: %Kind{name1: integer(), name2: integer(), name3: binary()} def unpack(input) do with…
Vivian
  • 1,539
  • 14
  • 38
1
vote
2 answers

Renaming Clojure's special forms

What's the best way to rename Clojure's special forms? For example, if I preferred defvar over def or defun over defn, what would be the best way to go about it?
Selam S
  • 43
  • 3
1
vote
2 answers

Scheme evaluating procedures and special forms

I have a question on the evaluation of Scheme, I just want to make sure I have a correct understanding on how procedures are evaluated. So when the Scheme interpreter starts to evaluate a list, the first element is evaluated, this has to evaluate to…
1
vote
2 answers

What would the consequences be of allowing special forms to be treated as normal values?

I discovered that special forms can not be passed as arguments or saved in variables, both in Clojure: user=> (defn my-func [op] (op 1 2 3)) #'user/my-func user=> (my-func +) 6 user=> (my-func if) java.lang.Exception: Unable to…
Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
0
votes
1 answer

How to use “and” with “seq-reduce” in Elisp?

I’m trying to write something like this: (setq l '(nil t nil nil)) (seq-reduce 'and l t) I get this error: Invalid function: and My understanding, after a bit of googling, is that this is due to and being a special form. What would be a good way…
-1
votes
2 answers

Primitive procedures and special forms in Scheme

In Scheme, are primitive procedures considered special forms? Also, a bit too general but how is define different from other special forms?
Tomer
  • 231
  • 2
  • 3
  • 8