Operator Overloading in Scheme and racket | INFJ Forum

Operator Overloading in Scheme and racket

endo

One
Feb 13, 2014
1
0
0
MBTI
fbzgdnsfghb
Hello. I am having some trouble here, and hopefully you guys can help.

Basically, what I am trying to do is overload the + sign in racket so that it will add two vectors instead of two numbers. I know this works in scheme, so I was told I needed to use module* to do it in racket.

Here is what I have so far:
#lang racket

(module* fun scheme/base
(define old+ +)
(define + new+)

(define (new+ x y)
(cond ((and (vector? x) (vector? y))
(quatplus x y))
(else (old+ x y))))

(define (quatplus x y)
(let ((z (make-vector 4)))
(vector-set! z 0 (old+ (vector-ref x 0) (vector-ref y 0)))
(vector-set! z 1 (old+ (vector-ref x 1) (vector-ref y 1)))
(vector-set! z 2 (old+ (vector-ref x 2) (vector-ref y 2)))
(vector-set! z 3 (old+ (vector-ref x 3) (vector-ref y 3)))
z)))

But it doesn't seem to do anything at all. If anyone knows anything about this I would be very appreciative.

Thank you.
 
Last edited:
Bleh. People who use LISP say it's not hard to understand. If that's the case then why are you here with such a simple problem? o.o Personally I don't get LISP. Does that mean I'm dumb? But it's supposed to be easy to understand and be the most powerful language. Shouldn't that mean that even I can get it?

I'd love to help and I'm really curious about this problem, and I understand what you're trying to do, I just don't understand LISP (Scheme/Racket)

It hurts my brain.
 
It's kind of a poor forum to ask this kind of question.

Try StackExchange or something.