Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add assignment operator macros #1320

Merged
merged 1 commit into from
Sep 27, 2021
Merged

Conversation

scolsen
Copy link
Contributor

@scolsen scolsen commented Sep 24, 2021

These macros apply an operation to the current value of a variable and
then set the variable to the result of the application. They are
effectively sugar for writing (set! <var> (<op> <var> <val>)) and
should be familiar to those who have programmed in imperative languages
like C.

In Carp, all the underlying operations these macros use are interfaces,
so one can flexibly use them for more than just numeric types.

Example usage:

(let-do [dial 0]
  ;; crank it up to 11!
  (while-do (< dial 12)
    (++ dial))
  dial)

;; expanded
(let-do [dial 0]
  ;; crank it up to 11!
  (while-do (< dial 12)
    (set! dial (inc dial)))
  dial)

These macros apply an operation to the current value of a variable and
then set the variable to the result of the application. They are
effectively sugar for writing `(set! <var> (<op> <var> <val>))` and
should be familiar to those who have programmed in imperative languages
like C.

In Carp, all the underlying operations these macros use are interfaces,
so one can flexibly use them for more than just numeric types.

Example usage:

```clojure
(let-do [dial 0]
  ;; crank it up to 11!
  (while-do (dial < 12)
    (++ dial))
  dial)

;; expanded
(let-do [dial 0]
  ;; crank it up to 11!
  (while-do (dial < 12)
    (set! dial (inc dial)))
  dial)
```
@scolsen scolsen requested a review from a team September 24, 2021 21:01
@hellerve
Copy link
Member

The example should read (< dial 12), right? Or am I missing some other context?

@scolsen
Copy link
Contributor Author

scolsen commented Sep 24, 2021

The example should read (< dial 12), right? Or am I missing some other context?

No additional context, you’re correct, that was my mistake. Writing too much go lately haha 🤦‍♂️

@scolsen
Copy link
Contributor Author

scolsen commented Sep 25, 2021

The example should read (< dial 12), right? Or am I missing some other context?

No additional context, you’re correct, that was my mistake. Writing too much go lately haha 🤦‍♂️

Fixed the PR comment, but my mistake will be forever etched in the eternal history of git log 🤷‍♂️

(Also 12 should technically be 11–that’ll teach me to attempt simple arithmetic when distracted)

@eriksvedang eriksvedang merged commit bd553fb into carp-lang:master Sep 27, 2021
@eriksvedang
Copy link
Collaborator

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants