# Different behavior racket/base vs. racket/hash

**URL:** <https://racket.discourse.group/t/different-behavior-racket-base-vs-racket-hash/4198>\
**Category:** Questions & Answers\
**Tags:** hash-tables\
**Created:** [May 7, 2026, 11:02pm UTC](https://racket.discourse.group/t/different-behavior-racket-base-vs-racket-hash/4198 "2026-05-07T23:02:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alsch](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alsch/32/2638_2.png) [@alsch](https://racket.discourse.group/u/alsch)\
**Post date:** [May 7, 2026, 11:02pm UTC](https://racket.discourse.group/t/different-behavior-racket-base-vs-racket-hash/4198/1 "2026-05-07T23:02:17Z")

</div>

How come:

```scheme
#lang racket
(define h (make-hash
           (list
            (list "a" 1)
            )
           )
)
(hash-ref h "a")

```

returns `'(1)` [a **list** of one element], but in Advanced Student Language:

```scheme
(define h (make-hash
           (list
            (list "a" 1)
            )
           )
)
(hash-ref h "a")

```

returns `1` [a simple value]?  
Is there any way to get the latter after using `(require racket)` (because I need other libraries from `racket`)?

Many thanks in advance,  
--Allan

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [May 7, 2026, 11:32pm UTC](https://racket.discourse.group/t/different-behavior-racket-base-vs-racket-hash/4198/2 "2026-05-07T23:32:59Z")

</div>

1. I quickly checked the relevant parts of the ASL implementation and found a note that I left behind years ago when I discovered how people had added hashes to ASL:

> ;; \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ;; MF: This design decision breaks one of the fundamental design guidelines for  
> ;; the teaching languages but it clearly has been in place for years. No going back.  
> ;; The correct design would have modified hash-ref and other observers of HASHes.  
> ;; \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

1. This brings me to issue a bit of a warning: ASL is essentially unsupported. Once we gave up on ASL for HtDP/2e, it became an experimentation language for certain courses.

2. If your question is whether you can get the `hash-ref` from racket into your code, adding `(require racket)` near the top will work.

3. If this is supposed to go to students, I recommend the creation of a teach pack that students then `require`. That way you can manage what you want to include from racket and what you want to exclude plus functions from other libs.

---

<div class="post-metadata">

**Author:** ![alsch](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alsch/32/2638_2.png) [@alsch](https://racket.discourse.group/u/alsch)\
**Post date:** [May 7, 2026, 11:42pm UTC](https://racket.discourse.group/t/different-behavior-racket-base-vs-racket-hash/4198/3 "2026-05-07T23:42:02Z")

</div>

Many thanks for you quick response.

I think we will just go with writing our own hash-ref that simply does a first on the return value from the original hash-ref.  
Unless that is a bad idea?

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [May 8, 2026, 12:32am UTC](https://racket.discourse.group/t/different-behavior-racket-base-vs-racket-hash/4198/4 "2026-05-08T00:32:21Z")

</div>

I am confused now. I thought you wanted racket's behavior in `#lang htdp/asl`.

Are you asking for something like

```scheme
(define (hash-ref/first h x)
  (define r (hash-ref h x))
  (if (cons? r) (first r) r))

```

---

<div class="post-metadata">

**Author:** ![shhyou](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@shhyou](https://racket.discourse.group/u/shhyou)\
**Post date:** [May 8, 2026, 12:33am UTC](https://racket.discourse.group/t/different-behavior-racket-base-vs-racket-hash/4198/5 "2026-05-08T00:33:55Z")

</div>

> [@alsch](#):
>
> I think we will just go with writing our own hash-ref that simply does a first on the return value from the original hash-ref.

FWIW, In Racket the association list for creating hashes,

```scheme
  (list
   (cons key1 value1)
   (cons key1 value2)
   ...)

```

is not a working program in \*SL because `cons` works on lists, not arbitrary pairs. Either \*SL has to use list of two-element lists or creates its own datatype for pairs:

```scheme
#lang htdp/isl+

(list
 (cons 'key1 'value1)
 (cons 'key2 'value2))

;; . . cons: second argument must be a list, but received 'key1 and 'value1
;; >

```

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [May 8, 2026, 1:11am UTC](https://racket.discourse.group/t/different-behavior-racket-base-vs-racket-hash/4198/6 "2026-05-08T01:11:49Z")

</div>

(Thanks @shhyou I should have explained my warning note in the ASL module more clearly.)

---

<div class="post-metadata">

**Author:** ![LiberalArtist](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/liberalartist/32/151_2.png) [@LiberalArtist](https://racket.discourse.group/u/LiberalArtist)\
**Post date:** [May 8, 2026, 3:07am UTC](https://racket.discourse.group/t/different-behavior-racket-base-vs-racket-hash/4198/7 "2026-05-08T03:07:12Z")

</div>

> [@alsch](#):
>
> Is there any way to get the latter after using `(require racket)` (because I need other libraries from `racket`)?

If you create a `racket-minus.rkt` like this:

```scheme
#lang racket
(provide (except-out (all-from-out racket)
                     make-hash))

```

then your main file can do:

```scheme
#lang htdp/asl
(require "racket-minus.rkt")
(define h
  (make-hash (list (list "a" 1))))
(check-expect (hash-ref h "a") 1)

```

* * *

In most Racket-family languages, I would tell you to write `(require (except-in racket make-hash))`, but the variant of `require` from `#lang htdp/asl` does not allow most `require` subforms:

```scheme
require: expected a module name as a string, a `lib' form, or a `planet' form, found a part in: (except-in racket make-hash)

```

Tangentially, the error message is not accurate, given that e.g. `(require 2htdp/image)` is allowed.

* * *

More broadly, I would be concerned that `(require racket)` would have confusing unintended consequences, since it will shadow _so many_ bindings from ASL, including `define`, `lambda` (adding Racket's optional and keyword arguments), and implicit bindings (e.g. `#%app` and `#%datum`, which control the meaning of function application and of literal data, respectively). I think you would be better off explicitly importing only what you need from Racket. (If you really wanted to, you could teach in `#lang racket` after/instead of ASL, but I found the teaching languages very helpful as a student.)

Concretely, along the lines of @shhyou's examples, `(require racket)` would shadow the definition of `cons` from ASL, so you _could_ instruct students to create hash tables with Racket-style association lists (but I am not claiming this would be good pedagogy):

```scheme
#lang htdp/asl
(require racket)
(define h
  (make-hash (list (cons "a" 1))))
(check-expect (hash-ref h "a") 1)

```
