0

I'm trying to take in an argument A and a list L in the function(consToAll A L) and cons the argument into every sublist of that list.

What is the best way of going about this?

This is the desired output:

If L is ( (1) (2) (3) ) then (consToAll 'a L) returns:

( (a 1) (a 2) (a 3) ).

Eggcellentos
  • 1,570
  • 1
  • 18
  • 25
Gavin Coll
  • 19
  • 4

2 Answers2

0

Treat 'a as a variable var
answered similar question here

replace f with var and funtion call (f (...)) with (cons var (car L))

Eggcellentos
  • 1,570
  • 1
  • 18
  • 25
0

R5RS/R6RS/R7RS have a built in 'map' procedure which will map over your list L. The easiest approach is to use that to cons A into each sublist.

Edit: Incidentally, be aware that your consToAll procedure will not as you think return '( (a 1) (a 2) (a 3) ), which is a literal constant, but will return a list of lists ( (a 1) (a 2) (a 3) ). See What is the difference between quote and list? .

Chris Vine
  • 677
  • 3
  • 7