0

i am trying to use string-prefix? but getting error unbound identifier in module

(string-prefix? "Racket" "R")

using drracket

please help

TzachiA
  • 13
  • 2

1 Answers1

3

TL;DR: add (require racket/string) at the second line of your file, and it will probably work.


Normally, this will work:

#lang racket

(string-prefix? "Racket" "R")

However, there are two possibilities why string-prefix? could be unbound.

  1. You are using a non-standard Racket language, and the language doesn't provide string-prefix?. An easy way to check if this is the case is to look at the first line of your program and see if you have #lang <lang-id> where <lang-id> is not racket. For instance:

    #lang racket/base
    
    (string-prefix? "Racket" "R")
    

    Here, string-prefix? is unbound because racket/base doesn't provide string-prefix?.

  2. You are using a special language. In this case, your program won't have #lang in the first line of your program, but the bottom-left corner will indicate the language that you are using (e.g., Beginning Student).

In both cases, if the language provides the require construct, then simply adding (require racket/string) will make string-prefix? available to you. This is because string-prefix? is defined in racket/string.

#lang racket/base

(require racket/string)

(string-prefix? "Racket" "R")
Sorawee Porncharoenwase
  • 6,305
  • 1
  • 14
  • 28