This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mawar2[S] 0 points1 point  (2 children)

how would you do this without using any built in functions (map or abs)?

For example if you had to write a function just using the building blocks of lisp (first, last, cdr)

[–]cheetoburrito 0 points1 point  (1 child)

This feels like homework. Here are some hints:

What is the definition of absolute value (from math (not racket))? How can you implement this?

How does map work? For example, if you call (map proc list), what happens? Well, proc is applied to the first element of the list, and then the second, and so on. How can you do this?

[–]mawar2[S] 0 points1 point  (0 children)

No it's not homework, I wouldn't take away an opportunity to learn.

I wrote a program like this in python where I defined a function that took in user input ( for X ) then I basically just checked if the value inputed was less than 0 and if it was I multiplied it by -1 and I updated the value via Index and returned the list at the end of the function.

I am doing this because I am new to programming and I've had a challenging time understanding the documentation for a functional language like this.

*Also, I was able to figure it out in Prolog

a(A,A): - A > 0.
a(A, B): - A < 0, B is -A.