Function:
(defun toggle(l)
(mapcar (lambda(x) (mod (+ x 1) 2)) l)
)
Toggle logic:
for each x do : (x+1)%2
mapcar operates on successive elements of the lists. function is applied to the first element of each list, then to the second element of each list, and so on.
Sample execution:
In Lisp programming language a 16. (20 pts.) Write a function that takes a list of...
LISP lambda calculate, expression 3) Consider reducing the following λ-expression to its normal form. Show the sequence of normal order reductions the sequence of applicative order reductions. · · 4) Consider the following function: Fx) ifx-0) then return 0 else return x+1 a) Express F as a lambda calculus expression b) Evaluate F(0) as a lambda expressiorn c) Evaluate F(1) as a lambda expression HINT: Use the representations introduces in Section 10. 5) Describe a function to compute the sum...
Write the function below in scheme/lisp programming language. Drracket Exercise: It is well known that n^2 is equal to the sum of the first n odd numbers. For example, 16 = 4^2 = 7 + 5 + 3 + 1. Write a function that takes as input a natural number, n, and that returns the square of its input by adding the first n odd numbers. Your code may not contain delayed operations and must use accumulative recursion.
1. Write a Lisp function called piece which takes a single argument x and implements the following piecewise linear function: piece(x) = x if 0 < x < 1 2. Write a Lisp function called intList which takes two integer arguments, a and b and returns the list of all integers from a to b (inclusive at both ends). For example, (intList 3 8) should return (345678) 1. Write a Lisp function called piece which takes a single argument x...
Using Python Programming Language: 3. Write a function flatten that takes a 2D list and returns all the items of each list concatenated together into one new 1D list. For example: flatten ([["a", "b"],["c","0"],["e","f"]]) would return ["a", "b","C","d", "e","f"] Save the function in a PyDev library module named functions.py Write a program t03.py that tests flatten function and prints the returned flat list to the screen. Test your program with a different list, hardcoded in t03.py • Copy the results...
2. Write a LISP function COUNTLETS which takes a list and returns the number of top-level alphabetic atoms in the list. For example: COUNTLETS ( (A 2) B 3 C4 (D 5))) Returns the value 2, the letters A and D are not at the top level
Submissions are accepted in program codes in C PROGRAMMING LANGUAGES COURSE ASSIGNMENT Design your own general purpose programming language which will be completely in english Your language design must include the following A general skeleton of a program State diagrams for the following (35 pts) . Identifier Unsigned integer Unsigned constant Constant Variable Factor and term rules similar to the ones given in your textbook Simple expression Compound expression . Parameter list Simple type 1D Array type Statement Block Loop...
PLEASE USE F# PROGRAMMING LANGUAGE: NO LOOPS OR CORE LIBRARY FUNCTIONS. ONLY USE RECURSION. Problem 3 (10 pts) Define a function rev that takes a list xs and returns it in the reverse order. • F# standard library has List.rev, do not use it. You need to reimplement it. In [ ]: let rev (xs: 'a list) In [ ]: // Test you function List.rev [] = rev [] |> printfn "%" List.rev [1..9] = rev [1..9] |> printfn "%b'...
#Swift programming language • For each: Implement a function forEach(array: [Int], _ closure: Int -> ()) that takes an array of integers and a closure and runs the closure for each element of the array. Example: var array = [1,2,3,4] forEach(array) { print($0 + 1) }
Please help with all four questions regarding LISP Programming. Thank you. Please answer all questions with output plesase. LISP Programming Assignment It is a good idea to start this assignment early; Lisp programming, while not inherently difficult, often seem somewhat foreign at first, particularly when it comes to recursion and list manipulation. This assignment is loosely based on material by Dr. Henri Casanova. Problem #1 Define a function that takes two arguments and returns the greater of the two. Problem...
Ouestion 1 (15 pts) Write a lisp function triangle that takes an argument (n) and shows a triangle of printed numbers as shown in the following samples. If the input is decimal or string, it should print an appropriate message (triangle 4) (triangle 5) 1 2 1 2 3 1 2 3 4 1 2 1 2 3 1 2 3 4 1 2 3 4 5 (triangle 2.5), decinal numbers are not valid input, please enter an integer